Skip to content

feat(report): reportUrl and techIconBaseUrl render options; reportInlineScripts() for a hash-based CSP (squirrelscan/repo#3182) - #1211

Merged
nc9 merged 2 commits into
mainfrom
feat/3182-renderer-report-url
Oct 28, 2026
Merged

nc9 merged 2 commits into
mainfrom
feat/3182-renderer-report-url

Conversation

@nc9

@nc9 nc9 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Public half of squirrelscan/repo#3182 step (c): what the cloud needs from the HTML renderer to serve published reports from per-org hosts on squirrel.report. No change for CLI reports: every option is new and opt-in, so REPORT_HTML_VERSION stays as it is.

Change (packages/report)

  • HtmlRenderOptions.reportUrl. The report's own URL. It is used for og:url, og:image (<url>/og.png), the agent .md/.json links, the report link in fix prompts, and a new <link rel="canonical">. Without it, a report with a reportId links to https://reports.squirrelscan.com/<id> and has no canonical link, exactly as before.
  • HtmlRenderOptions.techIconBaseUrl. Where technology logos load from, so a report page on another domain loads nothing from squirrelscan.com. The default is unchanged (https://squirrelscan.com/tech-icons). It is passed through a React context to the two TechIcon call sites, and techIconUrl(icon, base?) gains the optional base.
  • reportInlineScripts() returns the exact body of every executable inline <script> the report can render: copy/findings/pages/local-time, the notice dismiss, and the entity viewer. A host hashes them into script-src, so a script that is not ours never runs, even if an escaping bug let one into the page. The type="application/json" data blocks are not executable and not listed.

Tests

packages/report/tests/report-url-options-3182.test.ts (5):

  • Default: og and agent links on the reports host, no canonical.
  • With reportUrl: og, og:image, .md, .json and the canonical all use it, and the reports host never appears.
  • techIconBaseUrl: used, and the default is unchanged.
  • Inline scripts: renders a plain report, a coverage-notice report and an entity-map report. Every executable inline script must be in reportInlineScripts(), and every listed script must appear, so the list can be neither short nor stale.

bun run scripts/test-suites.ts --run report: 708 pass. Typecheck is ok for report and cli, and build:css:check reports styles up to date.

Docs: none; this is a library option the cloud uses, and CLI output is unchanged. CHANGELOG: Added. Skill: no change.

@claude

claude Bot commented Oct 27, 2026

Copy link
Copy Markdown

Review of #1211: the change is small and the default output stays the same. The test that the script list matches what is rendered is a good guard. I read the diff and did not run the tests.

  • (medium) packages/report/src/output/html.tsx:1475: reportUrl and techIconBaseUrl are used as given. AGENTS.md says to escape at the renderer and to canonicalize URLs a caller supplies. reportUrl goes into clickable <a href="${base}.md"> and .json links, plus <link rel="canonical"> and og:*. React escapes the attribute value, but a javascript: or other non-http(s) value would still render as a link. TechIcon already calls sanitizeUrl on the icon URL, but reportBase does not get the same treatment. Please run both options through new URL(v).href with an http(s)-only check, and fall back to the default or omit the value if it fails. Add a test for a bad scheme.
  • (low) packages/report/src/output/html.tsx:1475: a reportUrl with a trailing slash produces .../id/.md and .../id//og.png. techIconUrl trims trailing slashes, but reportUrl does not. Normalize it the same way, or document that it must not end in a slash.
  • (low) packages/report/src/output/html.tsx:1539: og:* tags are now emitted whenever base is set. A reportUrl passed without a reportId therefore also changes the OG block. That seems intended, but the docblock only describes the reportId case. State it.
  • (low) packages/report/src/output/html.tsx:2051: reportInlineScripts() hard-codes how the scripts are concatenated, which has to match the render path by hand. The test catches drift only for the fixtures it uses. Consider building the inline script tags and reportInlineScripts() from one shared list, so they cannot drift.
  • (nit) packages/report/tests/report-url-options-3182.test.ts: the reportUrl test has no case with offline: true. A one-line assertion would cover it.
  • (nit) The CHANGELOG bullet is fine, but the AGENTS.md format wants the issue reference at the end as (#123). The bullet ends with squirrelscan/repo#3182, which is in a different repo.

🤖 Generated with Claude Code

@nc9
nc9 force-pushed the feat/3182-renderer-report-url branch from f3fdc35 to e52a3b8 Compare October 28, 2026 03:17
@claude

claude Bot commented Oct 28, 2026

Copy link
Copy Markdown

Review of #1211. The change is small, opt-in and the CLI output stays the same. I found nothing blocking.

  • (medium) html.tsx (reportBase): reportUrl is used as-is. It goes into <link rel="canonical">, og:url, the .md/.json hrefs and the fix prompts. React escapes the attribute, but nothing checks the scheme. The report baseUrl, the screenshot and the favicon all go through sanitizeUrl/canonicalization, so this one should too. Reject anything that is not http(s), using new URL(v).href as AGENTS.md describes. The same applies to techIconBaseUrl. TechIcon does call sanitizeUrl on the final URL, so that one is covered. The host is trusted today, but a javascript: canonical or agent link is a cheap thing to rule out.
  • (low) A reportUrl with a trailing slash produces https://x//og.png and https://x/.md. techIconUrl already strips trailing slashes, so reportBase could do the same.
  • (low) reportUrl is also used when no reportId is set. That is probably intended, but coverageNoticeKey still keys on reportId. Please confirm the notice dismiss key stays stable for per-org hosts.
  • (nit) reportInlineScripts() hand-lists the script constants, so a new inline script can drift from it. The test catches this only for the three fixtures. Please add a note next to the script constants, or build the list from one registry.
  • (nit) Tests are missing for reportUrl with a trailing slash and with an invalid scheme. They would pin whichever behaviour you choose for the findings above.

@claude

claude Bot commented Oct 28, 2026

Copy link
Copy Markdown

Review of #1211: the change is small, opt-in and well tested. I found nothing blocking.

  • (low) html.tsx (reportBase): reportUrl is used as given, so a trailing slash produces //og.png and /.md. techIconUrl already strips trailing slashes, so I'd do the same here or document that the value must have none. The value also goes into href/content without sanitizeUrl, unlike other URLs in this file. It comes from the host, so this is probably fine, but a javascript: value would end up in the .md/.json hrefs. Restricting it to http(s) would keep the renderer safe on its own.
  • (low) html.tsx: with offline: true (the default) and a reportUrl, the canonical, og and agent links are still emitted. That matches the existing reportId behaviour, but the reportUrl doc comment could say so.
  • (low) reportInlineScripts(): the CSP hash list covers scripts only. The report inlines CSS and may use style attributes, so a host's style-src needs separate handling. It's worth a sentence in the doc comment.
  • (nit) The test for trailing-slash removal asserts <250ms. Per AGENTS.md, an effect assertion is preferred to a timing one, and this one could flake on a loaded CI runner. The 50k-slash input already shows the scan is linear.
  • (nit) There is no test where reportUrl is set without reportId. The code supports it, so that case is worth one assertion.

nc9 added 2 commits October 28, 2026 19:27
… and techIconBaseUrl; reportInlineScripts() lists the inline scripts for a hash-based CSP (squirrelscan/repo#3182)

Signed-off-by: Nik Cubrilovic <[email protected]>
…cktracking regex; the script test reads tags with HTMLRewriter (CodeQL 289, 290)

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the feat/3182-renderer-report-url branch from 90c7871 to 05bc2c3 Compare October 28, 2026 08:28
@claude

claude Bot commented Oct 28, 2026

Copy link
Copy Markdown

Review of #1211. The change is small, opt-in and CLI output is unchanged. I read the diff and the inline script sites in html.tsx. I did not run the tests or typecheck.

  • (medium) html.tsx ~1794: reportUrl goes straight into og:url, canonical and the .md/.json hrefs with no validation. React escapes the attribute, so this is not an injection. But a trailing slash gives .../id/.md and .../id//og.png, and a non-http(s) value would be published as is. The rest of this file runs URLs through sanitizeUrl, and AGENTS.md asks for new URL(v).href (http/https only) on URLs before printing them. Normalize reportUrl once: canonicalize it, require http(s), and strip trailing slashes. techIconBaseUrl is only partly covered, since TechIcon sanitizes the final URL but the base is not checked for scheme.
  • (low) reportInlineScripts() repeats the concatenation COPY_SCRIPT + FINDING_COPY_SCRIPT + PAGES_SCRIPT + LOCAL_TIME_SCRIPT that the render site uses at ~2361. If someone edits one of the two, the other drifts. The test would catch it, but sharing one constant is safer.
  • (low) A CSP hash needs byte-exact script bodies. renderToStaticMarkup with dangerouslySetInnerHTML does not alter them, and the test confirms that. The entityViewerScript() call at 1609 is the one site where I could not see whether it is a function of the report data. The test passes with one fixture, but a data-dependent body would break the hashes silently. Worth a comment next to it.
  • (nit) The perf assertion <250ms on the trailing-slash scan can flake under load. AGENTS.md prefers asserting an effect (the result is correct) over elapsed time, and the correctness check on the line above it already does that.
  • (nit) There is no test where reportUrl is given without reportId. That path now emits og tags (base && instead of reportId &&), so a test would pin the intended behavior.

@nc9
nc9 merged commit e038440 into main Oct 28, 2026
15 checks passed
@nc9
nc9 deleted the feat/3182-renderer-report-url branch October 28, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants