Skip to content

docs: pin jsDelivr SDK snippet with Subresource Integrity - #8990

Merged
khvn26 merged 10 commits into
mainfrom
docs/sri-jsdelivr-snippet
Nov 17, 2026
Merged

khvn26 merged 10 commits into
mainfrom
docs/sri-jsdelivr-snippet

Conversation

@khvn26

@khvn26 khvn26 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Changes

The quick start's jsDelivr <script> snippet had no Subresource Integrity (SRI) hash. If jsDelivr or @flagsmith/flagsmith on npm were compromised, readers' sites would run the attacker's code (see the Optimizely incident).

  • Snippets: both quick start snippets are pinned to an exact version, with integrity and crossorigin="anonymous" written in the page. Each sits under a Renovate marker, {/* renovate: datasource=npm depName=@flagsmith/flagsmith */}, which doesn't show on the rendered page. The page is renamed to .mdx so Prettier keeps the marker intact; the URL doesn't change.
  • Where the hash comes from: the npm release, not jsDelivr. The tarball is checked against the registry's dist.integrity, the file is extracted and hashed, and jsDelivr must serve exactly the same bytes.
  • Build check: the js-cdn-sri docs plugin finds snippets through the marker. It fails the build if a hash doesn't match the npm release or if jsDelivr serves different bytes. Any jsDelivr URL that isn't in a marked snippet with the exact tag form also fails the build. To fix hashes by hand, run npm run update-cdn-sri.
  • Renovate:
    • A regex custom manager reads the same marker to bump the version, once a release is 3 days old (minimumReleaseAge).
    • A post-upgrade task recomputes the hashes in the same PR.
    • The Renovate workflow allows only that command, via RENOVATE_ALLOWED_COMMANDS.
    • TODO: once Renovate's html manager supports jsDelivr (feat(datasource/jsdelivr): add new jsdelivr datasource renovatebot/renovate#45015, #26937), switch to it and drop the custom manager, the post-upgrade task and the allowed command.

How did you test this code?

  • CI=1 npm run build passes, and the pinned hash matches index.js from the npm tarball.
  • A stale hash fails the build, and npm run update-cdn-sri fixes it. Unmarked or non-standard jsDelivr tags fail it too.
  • With fetch patched to flip one bit, both a tampered jsDelivr file and a tampered npm tarball fail the build (even without CI), and update-cdn-sri refuses to write a hash.
  • A local Renovate dry run finds both snippets through the markers. With the snippets at 12.4.0, it marks the 12.5.0 bump ready with a 3-day minimum and holds it back with a 5-day minimum. renovate-config-validator accepts renovate.json.

The quick start loaded the JS SDK from jsDelivr without an integrity hash,
so a compromised CDN or npm release would run on readers' sites.

Compute a sha384 SRI hash for the pinned SDK version at build time and
render the snippet with integrity and crossorigin attributes. Add a tip
explaining why.
@khvn26
khvn26 requested a review from a team as a code owner November 17, 2026 08:36
@khvn26
khvn26 requested review from matthewelwell and removed request for a team November 17, 2026 08:36
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 17, 2026 10:24am UTC
2 Skipped Deployments
Project Deployment Actions Updated
flagsmith-frontend-preview Ignored Ignored Preview Nov 17, 2026 10:24am UTC
flagsmith-frontend-staging Ignored Ignored Preview Nov 17, 2026 10:24am UTC

Request Review

@github-actions github-actions Bot added the docs Documentation updates label Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The quick-start guide now shows version 12.5.0 jsDelivr SDK scripts with integrity attributes. New documentation tooling checks script integrity values and provides an update command. Renovate configuration detects SDK versions in documentation URLs and runs the update command for matching changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: Low · previous review a68c6

The change pins the quick-start SDK scripts with integrity hashes and adds a build check and an update command. Remaining issues are narrow edge cases in the tooling for unusual script-tag markup and do not affect normal documentation or production behavior. Merging is low risk, and the follow-ups can be addressed soon after.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

matthewelwell
matthewelwell previously approved these changes Nov 17, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1f893683-0936-4cda-b835-07b8a1fc2a1e
Commits

Reviewing files that changed from the base of the PR and between da995e7 and 858443a.

Files selected for processing: 4

  • docs/docs/getting-started/quick-start.md
  • docs/plugins/flagsmith-versions/index.js
  • docs/src/components/SdkVersions.js
  • docs/src/components/sdkVersionSpecs.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Computing the hash at build time trusted whatever jsDelivr served during
the build. Pin the SDK version and its hash in plugins/js-cdn-sri/pinned.json
instead, so changes go through review, and fail the build if jsDelivr
serves a file that doesn't match.

Bump the pin with `npm run update-js-cdn-sri [-- <version>]`.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread docs/plugins/js-cdn-sri/update.mjs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: b45e032d-ed10-4ab3-af6b-ed2f940d2dd0
Commits

Reviewing files that changed from the base of the PR and between 858443a and ab4d15a.

Files selected for processing: 7

  • docs/docusaurus.config.ts
  • docs/package.json
  • docs/plugins/js-cdn-sri/index.js
  • docs/plugins/js-cdn-sri/pinned.json
  • docs/plugins/js-cdn-sri/sri.mjs
  • docs/plugins/js-cdn-sri/update.mjs
  • docs/src/components/SdkVersions.js

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread docs/plugins/js-cdn-sri/update.mjs Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

Turn on auto-fix | Re-trigger cubic

Inline the pinned version and integrity hash in the quick start snippets
instead of rendering them from pinned.json, so the snippets are plain
code blocks.

A Renovate regex manager bumps @Flagsmith/flagsmith in docs jsDelivr URLs,
and a post-upgrade task (allowed in the Renovate workflow) recomputes the
integrity hashes on the same branch. The docs build fails if any jsDelivr
<script> snippet has no integrity attribute, or one that doesn't match what
jsDelivr serves.
@khvn26
khvn26 requested a review from a team as a code owner November 17, 2026 09:00
@khvn26
khvn26 requested review from emyller and removed request for a team November 17, 2026 09:00
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-8990 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-8990 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-8990 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-api:pr-8990 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith:pr-8990 Finished ✅ Results ✅
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8990 Finished ✅ Results ✅

@github-actions github-actions Bot added docs Documentation updates and removed docs Documentation updates labels Nov 17, 2026
Once renovatebot/renovate#45015 (jsDelivr datasource) and #26937 (jsDelivr
in the html manager) land, Renovate can update the SRI hashes itself and
the custom manager, post-upgrade task and allowed command can go.
@github-actions github-actions Bot added docs Documentation updates and removed docs Documentation updates labels Nov 17, 2026
@github-actions github-actions Bot added docs Documentation updates and removed docs Documentation updates labels Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 9 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread docs/plugins/js-cdn-sri/sri.mjs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 2b000703-0154-46d7-b3a8-36167186145a
Commits

Reviewing files that changed from the base of the PR and between 033437f and a68c609.

Files selected for processing: 3

  • docs/plugins/js-cdn-sri/index.js
  • docs/plugins/js-cdn-sri/sri.mjs
  • docs/plugins/js-cdn-sri/update.mjs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

Comment thread docs/plugins/js-cdn-sri/sri.mjs Resolved
Comment thread docs/plugins/js-cdn-sri/sri.mjs Resolved
Comment thread docs/plugins/js-cdn-sri/update.mjs Resolved
…HTML

Mark each jsDelivr snippet with the same comment Renovate uses to bump it,
{/* renovate: datasource=npm depName=<package> */}, and require one exact
<script> form inside marked blocks. The build check, the hash updater and
Renovate's regex manager all key off the marker, and any other jsDelivr URL
in the docs fails the build, so unusual HTML (unquoted or reordered
attributes) can't slip past the check.

Rename the quick start to .mdx so Prettier keeps the marker comment intact,
and let Renovate bump any marked npm package, not just the JS SDK.
@github-actions github-actions Bot added docs Documentation updates and removed docs Documentation updates labels Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread docs/plugins/js-cdn-sri/sri.mjs Resolved
Comment thread renovate.json Resolved
Comment thread docs/plugins/js-cdn-sri/sri.mjs Resolved
- Count jsDelivr URLs case-insensitively, as browsers treat hostnames, so
  e.g. CDN.JSDELIVR.NET can't bypass the SRI check.
- Fail on markers that aren't directly above a block with exactly one
  snippet, and stop Renovate's match at the end of the marked block, so a
  stale marker can't claim the next block's URL.
- Accept CRLF line endings around markers.
@github-actions github-actions Bot added docs Documentation updates and removed docs Documentation updates labels Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Requires human review: Auto-approval blocked by 3 unresolved issues from previous reviews.

Turn on auto-fix | Re-trigger cubic

CommonMark allows a closing fence to be indented by up to three spaces.
Neither the build check nor Renovate's match string recognised one, so a
marker above a CDN-free block closed that way could claim the next block's
unmarked jsDelivr URL. Treat such lines as the end of the block in both,
and only accept marked blocks opened with exactly three backticks.
@github-actions github-actions Bot removed the docs Documentation updates label Nov 17, 2026
@github-actions github-actions Bot added the docs Documentation updates label Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread docs/plugins/js-cdn-sri/sri.mjs Resolved
Hashing whatever jsDelivr returned made the CDN the trust anchor: tampered
bytes served when a hash was (re)computed would be pinned, and reviewers
can't meaningfully check a new base64 hash.

Hash the file from the npm tarball instead, after checking the tarball
against the registry's dist.integrity, and fail if jsDelivr serves
different bytes. Both the build check and the updater do this, and these
mismatches fail the build even when offline errors are tolerated locally.

Also make Renovate wait 3 days before bumping docs snippets, so a
compromised release is more likely to be caught before it's pinned.
@github-actions github-actions Bot added docs Documentation updates and removed docs Documentation updates labels Nov 17, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread docs/plugins/js-cdn-sri/sri.mjs Resolved
Comment thread docs/plugins/js-cdn-sri/index.js Resolved
@khvn26
khvn26 merged commit 4a45da1 into main Nov 17, 2026
33 of 37 checks passed
@khvn26
khvn26 deleted the docs/sri-jsdelivr-snippet branch November 17, 2026 10:46

This branch was successfully deployed

1 active deployment
Preview – docs — 5d1088ce Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants