chore: added openapi request adapting to ssl - #8133
Conversation
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoFix OpenAPI server URL generation to respect request protocol
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Proxy-spoofed OpenAPI scheme
|
| url:string | ||
| } => ({ | ||
| url: `${settings.ssl ? 'https' : 'http'}://${req.headers.host}${apiRoot}`, | ||
| url: `${req.protocol}://${req.headers.host}${apiRoot}`, |
There was a problem hiding this comment.
1. Proxy-spoofed openapi scheme 🐞 Bug ⛨ Security
generateServerForApiVersion() now uses req.protocol to select the scheme, which (when settings.trustProxy is enabled) can be influenced by X-Forwarded-Proto and cause the generated OpenAPI servers[0].url to advertise the wrong scheme under misconfigured/over-trusting proxy setups. Prefer settings.publicURL when configured (operator-trusted), and otherwise harden the fallback by whitelisting http/https and using Express’s host accessor (and optionally host validation) instead of raw headers.
Agent Prompt
### Issue description
`generateServerForApiVersion()` now builds the OpenAPI server URL using `req.protocol`, which becomes proxy-header-derived when `trustProxy` is enabled. This can cause the served OpenAPI document to advertise an incorrect scheme if proxy headers are missing/spoofed or the instance is reachable without a trusted proxy in front.
### Issue Context
The codebase already has an operator-trusted `settings.publicURL` intended to avoid client-controlled origin values, and `socialMeta.ts` demonstrates a hardened approach (prefer `publicURL`, otherwise validate host/proto).
### Fix Focus Areas
- src/node/hooks/express/openapi.ts[868-872]
- src/node/utils/Settings.ts[411-421]
- src/node/utils/socialMeta.ts[139-155]
- src/node/hooks/express.ts[157-165]
### Suggested fix
1) If `settings.publicURL` is set and valid, use it as the origin for `servers[0].url` (append `apiRoot`).
2) Else, keep the request-derived fallback but harden it:
- Allow only `http` or `https` (fallback to `'http'` if unexpected).
- Use `req.get('host')` instead of `req.headers.host` for consistency with other code paths.
- (Optional but safer) validate/sanitize the host similarly to `socialMeta.ts`’s `sanitizeHost()` before emitting it into the OpenAPI document.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Closes #8129