Skip to content

fix(rules): security/sri exempts Shopify platform scripts and adds exempt_hosts #546 - #879

Merged
nc9 merged 1 commit into
mainfrom
fix/546-sri-shopify-exempt
Oct 16, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/546-sri-shopify-exempt

Conversation

@nc9

@nc9 nc9 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Closes #546

What changed

  • security/sri exempts cdn.shopify.com by path prefix, /shopifycloud/ and /storefront/: Shopify injects those scripts into every store and updates them in place. The rest of cdn.shopify.com (theme assets under /s/files/, theme app extensions under /extensions/) is still checked.
  • New rule option exempt_hosts (array of bare hostnames, matched exactly, ignoring case and a terminal dot). Validated by its zod schema, so squirrel config validate and the audit preflight name a bad entry: [rule_options."security/sri"] exempt_hosts.0: must be a hostname such as static.example.com, with no scheme, port or path.
  • The eleven built-in hostnames are unchanged (the docs still say eleven, plus the two Shopify paths).
  • The solution text and docs now point at exempt_hosts instead of "disable the rule" for a self-updating script.

Acceptance criteria

  • cdn.shopify.com/shopifycloud/ and /storefront/ scripts not reported
  • exempt_hosts documented (Options table + example) and validated
  • Versioned third-party script without integrity still flagged
  • cdn.shopify.com theme/app asset outside the prefixes still flagged
  • sri.mdx lists the path-prefix exemptions and the option
  • Tests in packages/rules/tests/sri.test.ts: the two Shopify URLs not reported; a theme asset with ?v= and an -latest app extension reported; cdn.jsdelivr.net/npm/[email protected]/x.js reported; a listed host not reported, an unlisted one reported; option validation; prefix only from the path start
  • Existing exempt-hostname cases green
  • Skill: no change needed (the skill links to the rule page, which documents the option).

Typecheck (rules), oxlint on changed files, sri, rule-options-check, template-verdict-inputs, noscript-content tests pass, codex review (2 rounds, clean).

…empt_hosts #546

cdn.shopify.com /shopifycloud/ and /storefront/ are exempt by path prefix;
theme and app assets elsewhere on the host are still checked. exempt_hosts
takes bare hostnames, validated by config validate and the audit preflight.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/546-sri-shopify-exempt branch from 6c23d42 to 7588c82 Compare October 16, 2026 23:10
@nc9
nc9 marked this pull request as ready for review October 16, 2026 23:10
@claude

claude Bot commented Oct 16, 2026

Copy link
Copy Markdown

Reviewed the diff for security/sri: the Shopify path exemptions and the new exempt_hosts option. I found no blocking problems.

  • (nit) packages/rules/tests/sri.test.ts: there is a double blank line before the new describe block.
  • (nit) packages/rules/src/security/sri.ts: optionsSchema.parse(ctx.options) and new Set(...) run on every page. The cost is trivial, but the set could be cached per options object. Other rules, such as adblock/element-hiding, parse per run in the same way, so this is fine to leave.
  • (low) security/sri.ts: the Shopify exemption relies on URL.pathname for matching. WHATWG URL parsing already normalizes .. segments, so a path like /shopifycloud/../s/files/x.js resolves to /s/files/x.js and is correctly still flagged. A test for that would document the behavior.
  • (low) The hostname regex accepts a single-label host such as localhost, which is fine. It also accepts IP-looking values like 1.2.3.4; that is harmless, since IPv4 hosts match exactly.

What I checked:

  • Both host exemptions and path prefixes are normalized through hostKey, so case and a terminal dot are handled for built-in and user hosts alike. The tests cover this.
  • The CHANGELOG and docs match the behavior.
  • Coverage is good: the /s/files/shopifycloud/ prefix-anchoring case, the config-validation errors and the dotted-host case are all tested.

@nc9

nc9 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Review triage (7588c82): no change pushed. The double blank line and the per-page options parse are cosmetic; the latter matches the other rules that take options. The .. normalisation and IP-literal hosts behave as the review describes, and neither needs a change.

@nc9
nc9 merged commit 09bdc44 into main Oct 16, 2026
16 checks passed
@nc9
nc9 deleted the fix/546-sri-shopify-exempt branch October 16, 2026 23:46
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.

security/sri: exempt Shopify platform scripts and add an exempt_hosts option

1 participant