You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docs: pin jsDelivr SDK snippet with Subresource Integrity - #8990
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.
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.
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.
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.
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.
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>]`.
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.
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.
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.
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.
…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.
- 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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
The quick start's jsDelivr
<script>snippet had no Subresource Integrity (SRI) hash. If jsDelivr or@flagsmith/flagsmithon npm were compromised, readers' sites would run the attacker's code (see the Optimizely incident).integrityandcrossorigin="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.mdxso Prettier keeps the marker intact; the URL doesn't change.dist.integrity, the file is extracted and hashed, and jsDelivr must serve exactly the same bytes.js-cdn-sridocs 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, runnpm run update-cdn-sri.minimumReleaseAge).RENOVATE_ALLOWED_COMMANDS.htmlmanager 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 buildpasses, and the pinned hash matchesindex.jsfrom the npm tarball.npm run update-cdn-srifixes it. Unmarked or non-standard jsDelivr tags fail it too.fetchpatched to flip one bit, both a tampered jsDelivr file and a tampered npm tarball fail the build (even withoutCI), andupdate-cdn-srirefuses to write a hash.renovate-config-validatoracceptsrenovate.json.