Skip to content

Commit beae994

Browse files
committed
security(x402): SRI-pin the Scalar bundle on the public /api page
The /api OpenAPI reference is served over the public tunnel and pulls the @scalar/api-reference bundle from jsdelivr. The integrity hash was left empty in phase 1, so the browser executed whatever the CDN returned, unverified. Populate scalarBundleSRI with the sha384 of the pinned 1.34.0 bundle so a tampered CDN response is blocked. Comment updated to stress the hash must be re-derived in lockstep with every scalarBundleVersion bump.
1 parent a38db07 commit beae994

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

internal/serviceoffercontroller/scalar_html.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ package serviceoffercontroller
66
const scalarBundleVersion = "1.34.0"
77

88
// scalarBundleSRI is the Subresource Integrity hash for the pinned bundle.
9-
// Left empty in phase 1 — the bundle still loads, browsers just skip the
10-
// integrity check. Populate by running:
9+
// The /api page is served over the public tunnel, so the third-party Scalar
10+
// JS it pulls from jsdelivr must be integrity-checked: without this the
11+
// browser executes whatever the CDN returns, unverified. Re-derive on every
12+
// version bump (Renovate touches scalarBundleVersion above) by running:
1113
//
1214
// curl -sL https://cdn.jsdelivr.net/npm/@scalar/api-reference@<version> \
1315
// | openssl dgst -sha384 -binary | base64
1416
//
15-
// and prefixing the result with `sha384-`. Re-derive on every version bump.
16-
const scalarBundleSRI = ""
17+
// and prefixing the result with `sha384-`. The hash is taken over the exact
18+
// (jsdelivr-minified) bytes that the pinned URL serves; it must be refreshed
19+
// in lockstep with scalarBundleVersion or the browser will block the script.
20+
const scalarBundleSRI = "sha384-tNJHhVh8smfB4VJcBxQf3Q0Soj15UqqyVJ6Q6OTwqGVEyxy57gfDLo7DGcSclH7I"
1721

1822
// scalarHTML returns the static HTML shell served at /api. It loads the
1923
// pinned @scalar/api-reference bundle from jsdelivr, points it at the

0 commit comments

Comments
 (0)