Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ exports.handler = (event, context, callback) => {

// Docs used to be under /doc, so redirect those for now
if (request.uri.startsWith('/doc/')) {
return redirect(request.uri.slice(4), callback);
// Collapse repeated slashes to prevent open redirect vulnerabilities.
// E.g. this prevents paths like `/doc//example.com` from redirecting
// to `https://example.com`.
const redirectTarget = request.uri.slice(4).replace(/\/+/g, '/');

return redirect(redirectTarget, callback);
}

// The `/stable`, `/beta`, and `/nightly` urls are all workable as-is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ test("example expected redirects", async (t) => {
// /doc
{ from: "/doc/std", to: "/std" },
{ from: "/doc/hello", to: "/hello" },
// Test that repeated slashes are collapsed to prevent open redirect vulnerabilities
{ from: "/doc//example.com/something", to: "/example.com/something" },
];

for (const redir of redirects) {
Expand Down
Loading