Repository navigation
warn about missing SSRF protection config in angular v22 - #10523
Conversation
Angular 22 enabled strict SSRF protection on its SSR engine. Without explicit configuration, Firebase Hosting SSR functions will return errors due to rotating Cloud Run hostnames. - Add security pre-flight check for Angular 22 SSR builds - Detect missing `security.allowedHosts` in angular.json - Detect missing `trustProxyHeaders` in server entry point - Surface cohesive, indented warnings with links to official docs - Add unit tests
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
There was a problem hiding this comment.
Code Review
This pull request implements a security pre-flight check for Angular 22 SSR projects to ensure they are correctly configured for Firebase Hosting. It adds logic to detect missing allowedHosts and trustProxyHeaders settings, which are necessary for SSR to work with Cloud Run's rotating hostnames. Feedback from the review focuses on improving the accuracy of configuration detection through more specific regex patterns, optimizing build performance by eliminating redundant context resolution, and increasing robustness by dynamically identifying the server entry point from project metadata instead of relying on hardcoded file paths.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a security pre-flight check for Angular 22 SSR deployments on Firebase Hosting. It adds logic to detect missing security.allowedHosts and trustProxyHeaders configurations, which are required for strict SSRF protection in Angular 22. The implementation includes new utility functions in src/frameworks/angular/utils.ts and comprehensive unit tests in src/frameworks/angular/utils.spec.ts. Feedback was provided regarding the robustness of the regex patterns used to detect configuration in the server entry file, as they may currently match occurrences within comments.
|
|
||
| const declared = opts.buildOptionsAllowedHosts ?? []; | ||
| const serverHasAllowedHosts = | ||
| !!opts.serverEntrySource && /\ballowedHosts\s*[:=]/.test(opts.serverEntrySource); |
There was a problem hiding this comment.
| } | ||
|
|
||
| const trustProxyHeadersMissing = | ||
| !opts.serverEntrySource || !/\btrustProxyHeaders\s*[:=]/.test(opts.serverEntrySource); |
Treated allowedHosts and trustProxyHeaders as two independent requirements, so it warned even when the deploy would work (e.g. allowlisting *.a.run.app with no trustProxyHeaders). Collapse to one check: is the Host the SSR engine validates allowlisted? trustProxyHeaders just selects which Host that is, not a second must-have. Recommend the full host set, show trustProxyHeaders only as an alternative, and note custom domains there. Verified on Angular 22.0 GA
931c096 to
aa831c0
Compare
* security(angular): warn about missing SSRF protection config in v22 Angular 22 enabled strict SSRF protection on its SSR engine. Without explicit configuration, Firebase Hosting SSR functions will return errors due to rotating Cloud Run hostnames. - Add security pre-flight check for Angular 22 SSR builds - Detect missing `security.allowedHosts` in angular.json - Detect missing `trustProxyHeaders` in server entry point - Surface cohesive, indented warnings with links to official docs - Add unit tests * fixes, PR comments, refactors * fix: warn about Angular 22 SSRF config only when the host is rejected Treated allowedHosts and trustProxyHeaders as two independent requirements, so it warned even when the deploy would work (e.g. allowlisting *.a.run.app with no trustProxyHeaders). Collapse to one check: is the Host the SSR engine validates allowlisted? trustProxyHeaders just selects which Host that is, not a second must-have. Recommend the full host set, show trustProxyHeaders only as an alternative, and note custom domains there. Verified on Angular 22.0 GA * check version earlier * changelog * minor update in warning message
) * security(angular): warn about missing SSRF protection config in v22 Angular 22 enabled strict SSRF protection on its SSR engine. Without explicit configuration, Firebase Hosting SSR functions will return errors due to rotating Cloud Run hostnames. - Add security pre-flight check for Angular 22 SSR builds - Detect missing `security.allowedHosts` in angular.json - Detect missing `trustProxyHeaders` in server entry point - Surface cohesive, indented warnings with links to official docs - Add unit tests * fixes, PR comments, refactors * fix: warn about Angular 22 SSRF config only when the host is rejected Treated allowedHosts and trustProxyHeaders as two independent requirements, so it warned even when the deploy would work (e.g. allowlisting *.a.run.app with no trustProxyHeaders). Collapse to one check: is the Host the SSR engine validates allowlisted? trustProxyHeaders just selects which Host that is, not a second must-have. Recommend the full host set, show trustProxyHeaders only as an alternative, and note custom domains there. Verified on Angular 22.0 GA * check version earlier * changelog * minor update in warning message
Description
Angular 22 enables strict SSR host validation by default. On Firebase Hosting Web Frameworks, SSR runs on Cloud Run behind a proxy with rotating hostnames, so without the right security.allowedHosts configuration the SSR responses start failing after deploy — a problem that never shows up locally and is hard to diagnose.
This PR adds a build-time pre-flight check for Angular 22 SSR projects. It asks one question — will the host the SSR engine actually validates be allowlisted? — where trustProxyHeaders just selects which host that is: the forwarded public domain when on, the raw Cloud Run host when off. When that host is missing it prints an actionable warning (with links to the official Angular docs) listing the hosts to add, and surfaces trustProxyHeaders only as an alternative. The check is best-effort and informational — it never blocks or fails the build, and it does nothing for older Angular versions, non-SSR apps, or already-configured projects.
Scenarios Tested
firebase deploy
Sample Commands