Commit 812e774
committed
refactor(@angular/ssr): enforce explicit opt-in for proxy headers
This commit introduces a secure-by-default model for trusting proxy
headers (`X-Forwarded-*`) in the `@angular/ssr` package. Previously, the
engine relied on complex lazy header patching and regex filters to guard
against spoofed headers. However, implicit decoding behaviors by URL
constructors can render naive regex filtering ineffective against certain
percent-encoded payloads.
To harden the engine against Server-Side Request Forgery (SSRF) and
header-spoofing attacks:
- Introduced the `allowedProxyHeaders` configuration option to
`AngularAppEngineOptions` and `AngularNodeAppEngineOptions`.
- By default (`false`), all incoming `X-Forwarded-*` headers are aggressively
scrubbed unless explicitly whitelisted via `allowedProxyHeaders`.
- Replaced the lazy `cloneRequestAndPatchHeaders` utility with a simplified,
eager `sanitizeRequestHeaders` that centralizes the header scrubbing logic.
- Hardened `verifyHostAllowed` to definitively reject parsed hosts that successfully
carry path, search, hash, or auth components, replacing previously fallible
regex filters for stringently checked hosts.
BREAKING CHANGE:
The `@angular/ssr` package now ignores all `X-Forwarded-*` proxy headers by default. If your application relies on these headers (e.g., for resolving absolute URLs, trust proxy, or custom proxy-related logic), you must explicitly allow them using the new `allowedProxyHeaders` option in the application server configuration.
Example:
```ts
const engine = new AngularAppEngine({
// Allow all proxy headers
allowedProxyHeaders: true,
});
// Or explicitly allow specific headers:
const engine = new AngularAppEngine({
allowedProxyHeaders: ['x-forwarded-host', 'x-forwarded-prefix'],
});
```1 parent 3663f80 commit 812e774
File tree
9 files changed
+242
-297
lines changed- goldens/public-api/angular/ssr
- node
- packages/angular/ssr
- node
- src
- test
- src
- utils
- test
- utils
9 files changed
+242
-297
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
| |||
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
30 | 43 | | |
31 | 44 | | |
32 | 45 | | |
33 | 46 | | |
| 47 | + | |
34 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
35 | 54 | | |
36 | 55 | | |
37 | 56 | | |
38 | 57 | | |
39 | | - | |
| 58 | + | |
40 | 59 | | |
41 | | - | |
| 60 | + | |
42 | 61 | | |
43 | 62 | | |
44 | 63 | | |
| |||
49 | 68 | | |
50 | 69 | | |
51 | 70 | | |
| 71 | + | |
52 | 72 | | |
53 | 73 | | |
54 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
55 | 78 | | |
56 | 79 | | |
57 | 80 | | |
58 | 81 | | |
59 | 82 | | |
60 | 83 | | |
61 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
62 | 89 | | |
63 | 90 | | |
64 | 91 | | |
| |||
75 | 102 | | |
76 | 103 | | |
77 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
78 | 112 | | |
79 | 113 | | |
80 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
81 | 118 | | |
82 | 119 | | |
83 | 120 | | |
84 | 121 | | |
85 | 122 | | |
86 | 123 | | |
| 124 | + | |
87 | 125 | | |
88 | | - | |
89 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
90 | 129 | | |
91 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
92 | 135 | | |
93 | 136 | | |
94 | 137 | | |
95 | 138 | | |
96 | 139 | | |
97 | 140 | | |
98 | | - | |
| 141 | + | |
99 | 142 | | |
100 | 143 | | |
101 | 144 | | |
| |||
104 | 147 | | |
105 | 148 | | |
106 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| 156 | + | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
25 | 41 | | |
26 | 42 | | |
27 | 43 | | |
| |||
78 | 94 | | |
79 | 95 | | |
80 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
81 | 102 | | |
82 | 103 | | |
83 | 104 | | |
| |||
89 | 110 | | |
90 | 111 | | |
91 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
92 | 119 | | |
93 | 120 | | |
94 | 121 | | |
| |||
132 | 159 | | |
133 | 160 | | |
134 | 161 | | |
| 162 | + | |
135 | 163 | | |
136 | 164 | | |
137 | | - | |
| 165 | + | |
138 | 166 | | |
139 | | - | |
| 167 | + | |
140 | 168 | | |
141 | 169 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | 170 | | |
148 | 171 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 172 | + | |
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
| |||
0 commit comments