Commit 286a79d
Merge commit from fork
* Fix CSP directive injection in sandbox / plugin-types / report-to (GHSA-rqq5-2gf9-4w4q)
The 2020 source-list scrub (gsub /[\n;]/) was not applied to three
caller-byte-interpolating builders:
- build_sandbox_list_directive
- build_media_type_list_directive (plugin-types)
- build_report_to_directive
When any of those caller-supplied values contained a `;` or CR/LF,
the bytes landed verbatim in the Content-Security-Policy header.
Because sandbox and plugin-types are emitted in alphabetical order
before script-src, an injected `; script-src 'unsafe-inline' *`
wins via CSP's first-occurrence rule and disables script-src.
Mirror the existing source-list scrub: replace `;`, `\n`, `\r` with a
space and emit a Kernel.warn (same UX as build_source_list_directive).
Adds three regression specs covering all three builders.
Co-Authored-By: tonghuaroot <tonghuaroot@gmail.com>
Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>
* Apply review feedback: unify source-list scrub, single warn per directive
Three refinements to the GHSA fix:
1. Unify the legacy build_source_list_directive scrub with the new
scrub_directive_value helper. The new helper's regex is [\n\r;]
(strict superset of the legacy [\n;]); routing the source-list
path through it closes the bare-\r smuggling gap on naive
downstreams without expanding the fix surface.
2. Scrub the joined directive string once instead of per-token, so
high-cardinality input emits a single Kernel.warn per directive
rather than N warns. Removes scrub_directive_tokens entirely
(only caller was the per-token map). Behavior pinned by a new
spec that asserts exactly one warn for a 3-semicolon input.
3. Move the helper docstring above the method it documents (it was
above the constant). Reword to reflect the per-directive warn
contract.
Side effect of (1): two existing source-list deprecation specs
asserted the legacy warn format (contains a ;); the unified helper
uses $~[0].inspect (contains a ";") which renders \n as "\n" in the
warning rather than embedding a literal newline. Updated the two
pre-existing expectations to match — the new format is unambiguously
more readable for humans and the GHSA-fix author already chose
.inspect for the new helper.
Tests: 321 examples, 0 failures (+2 new regression specs: source-list
\r injection, single-warn semantics).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Close test gaps: pin sandbox warn text + add report-only regression spec
Two follow-ups on the review's test-coverage thread:
1. Tightened the sandbox-injection spec from allow(Kernel).to
receive(:warn) to expect(...).to receive(:warn).with(...).once.
Pins both halves of the contract: the scrub neutralizes the
injection AND the deprecation warning fires exactly once per
offending value. Catches a future regression where someone
reverts the joined-string scrub to per-token (which would emit
N warns instead of 1).
2. Added a report-only regression spec. Content-Security-Policy
builds value through the same #value method regardless of
:report_only, so the existing fix transparently covers
Content-Security-Policy-Report-Only — but no spec asserts
that. A future refactor that split the enforced and
report-only builders could silently leave Report-Only
exploitable while the enforced spec stayed green.
Tests: 322 examples, 0 failures.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: Matt Langlois <fletchto99@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent c29127f commit 286a79d
2 files changed
Lines changed: 106 additions & 11 deletions
File tree
- lib/secure_headers/headers
- spec/lib/secure_headers/headers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
109 | 131 | | |
110 | 132 | | |
111 | 133 | | |
| |||
118 | 140 | | |
119 | 141 | | |
120 | 142 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 143 | + | |
127 | 144 | | |
128 | 145 | | |
129 | 146 | | |
| |||
Lines changed: 80 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
246 | 324 | | |
247 | 325 | | |
248 | 326 | | |
0 commit comments