Repository navigation
fix(waf-detect): recover from unclosed quote elements - #905
WilliamK112 wants to merge 1 commit into
Conversation
Signed-off-by: Ching-Wei Kang <[email protected]>
|
Thanks for picking this up, and for the clear boundary list. One change is needed before we can merge. A block opened inside the quote now ends the quote. The reset fires on any closing boundary tag. A <pre><code><div class="ec-line"><div class="code">curl -I x</div></div><div class="ec-line"><div class="code">Request unsuccessful. Incapsula incident ID: 1234000280151781213-1234</div></div></code></pre>On main, The HTML parser only closes an open
Please add a test with the nested- |
…'s end #904 (#916) Closes #904 Thank you @WilliamK112 for #905, which tackled the same problem and helped confirm the fix was needed. This PR takes a slightly different route so that code blocks built from nested blocks, such as Expressive Code and Starlight, keep their lines treated as quoted. ## What changed `signatureViews` in `packages/waf-detect/src/views.ts` drops the text inside `<code>`, `<kbd>` and `<samp>` from the text view. Before this change, an unclosed `<code>` hid every word after it in the sample. The browser instead closes it at the end of its block. Now: - a block-level end tag (`</p>`, `</div>`, `</pre>`, `</li>`, `</td>`, `</body>` and the like) ends any quote still open inside that block; - a block opened inside the quote is counted. Its own end tag closes only that block, not the quote around it. Without this, a code block that wraps each line in a `<div>`, as Expressive Code (Starlight) does, would expose its quoted lines to the text view. ## Tests `packages/waf-detect/tests/content-signatures.test.ts`, 155/155: - a stray `<code>` before an Imperva incident line: attributed to Imperva - an unclosed `<kbd>` in a list item before a Cloudflare ray id: attributed to Cloudflare - a properly closed `<pre><code>` quoting the incident line: not attributed - `<pre><code><div>log</div>…incident line…</code></pre>`: not attributed - an Expressive Code block (`<figure><pre><code><div class="ec-line">…</div></code></pre></figure>`) quoting an incident line and a ray id: n
|
Thanks for taking this on, @WilliamK112, and for the clear tests. While reviewing we found that resetting on any closing block tag lets a block opened inside the code (the per-line divs Expressive Code and Starlight emit) end the quote early, so we landed a fix that counts blocks opened inside the quote (#916) and are closing this one as superseded. The reviewer's notes on the edge case are in the thread above. Your other PRs are being merged separately. |
Summary
code,kbd, andsampquote regions at closing block boundariesTesting
npm exec --yes --cache /tmp/squirrelscan-904-npm-cache [email protected] -- bun test packages/waf-detect/testsnpm exec --yes --cache /tmp/squirrelscan-904-npm-cache --package=@typescript/[email protected] -- tsgo -p packages/waf-detect/tsconfig.json --noEmitCloses #904