Skip to content
Open
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
39 changes: 23 additions & 16 deletions src/http/output/PivotResponseWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@ export class PivotResponseWriter extends BasicResponseWriter {
if (
(input.response.req.method === 'GET') &&
(typeof input.response.req.url === 'string') &&
([401, 403, 404].indexOf(input.result.statusCode) !== -1) &&
(hasTrailingSlash(input.response.req.url) === false)) {
([401, 403, 404].indexOf(input.result.statusCode) !== -1)
) {
const target = await this.targetExtractor.handleSafe({ request: input.response.req as HttpRequest });
const withSlash = addTrailingSlash(target.path);
let exists = false;
try {
exists = await this.store.hasResource({ path: withSlash });
} catch (e) {
// leave as false
}
// console.log('exists', withSlash, exists);
if (exists) {
// console.log('rewriting', input.response.req.method, input.response.req.url, input.result.statusCode);
input.response.statusCode = 301;
input.response.setHeader('Location', withSlash);
input.response.end('Try adding a slash at the end of the URL.\n');
return;
// Only canonicalize when the identifier path genuinely lacks a trailing slash.
// The raw request URL includes the query string, so checking it would treat
// OIDC redirects (e.g. /?code=...&state=...) as missing a slash and redirect
// to a query-less "//" URL, dropping the authorization code and breaking
// login on private containers.
if (!target.path.endsWith('/')) {
const withSlash = addTrailingSlash(target.path);
let exists = false;
try {
exists = await this.store.hasResource({ path: withSlash });
} catch (e) {
// leave as false
}
// console.log('exists', withSlash, exists);
if (exists) {
// console.log('rewriting', input.response.req.method, input.response.req.url, input.result.statusCode);
input.response.statusCode = 301;
input.response.setHeader('Location', withSlash);
input.response.end('Try adding a slash at the end of the URL.\n');
return;
}
}
}
} catch (e) {
Expand Down
Loading