-
Notifications
You must be signed in to change notification settings - Fork 9
fix: use request.headers.host (with port) in buildResourceUrl #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ import { generateDatabrowserHtml, generateModuleDatabrowserHtml } from '../mashl | |
| * @returns {string} Normalized resource URL | ||
| */ | ||
| function buildResourceUrl(request, urlPath) { | ||
| // Use request.headers.host (includes port) instead of request.hostname (strips port) | ||
| const host = request.headers.host || request.hostname; | ||
| if (request.subdomainsEnabled && request.baseDomain && | ||
| request.hostname === request.baseDomain && !request.podName) { | ||
| const pathMatch = urlPath.match(/^\/([^/]+)(\/.*)?$/); | ||
|
|
@@ -33,7 +35,7 @@ function buildResourceUrl(request, urlPath) { | |
| return `${request.protocol}://${podName}.${request.baseDomain}${remainder}`; | ||
| } | ||
|
Comment on lines
29
to
36
|
||
| } | ||
| return `${request.protocol}://${request.hostname}${urlPath}`; | ||
| return `${request.protocol}://${host}${urlPath}`; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -180,7 +182,7 @@ function getErrorPage(statusCode, isAuthenticated, request) { | |
| ? "This resource is protected. You'll need to sign in to continue." | ||
| : "You're signed in, but you don't have permission to view this resource."; | ||
|
|
||
| const baseUrl = `${request.protocol}://${request.hostname}`; | ||
| const baseUrl = `${request.protocol}://${request.headers.host || request.hostname}`; | ||
|
|
||
|
Comment on lines
+185
to
186
|
||
| return `<!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildResourceUrlis used for WAC authorization decisions, but this change switches torequest.headers.hostdirectly. The Host header (and withtrustProxy: true, proxy-provided host headers) is client-influenced and can be spoofed, which risks incorrect ACL matching across virtual hosts. Consider deriving the authority from Fastify’s trusted properties and only appending a validated port (or validating thatheaders.hostmatchesrequest.hostname), and includex-forwarded-hostwhen running behind a proxy (consistent withsrc/ap/index.js:70-78).