Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
- name: Install dependencies
run: npm ci

# Only shipped dependencies gate the build. Advisories confined to the
# dev-only test toolchain (Azurite and its transitives) are tracked in
# docs/securityscan.md rather than blocking every pull request.
- name: Audit runtime dependencies
run: npm audit --omit=dev --audit-level=low

- name: Check formatting
run: npm run format:check

Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ concurrency:
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
manifest-digest: ${{ steps.manifest.outputs.digest }}
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}
Expand Down Expand Up @@ -71,6 +73,17 @@ jobs:
- name: Prepare and verify the release tarball
run: npm run release:pack -- -- --require-clean --require-main-ancestor --require-release-tag --expected-release-commit "${RELEASE_COMMIT}" --output .release

# Crosses the job boundary through run metadata rather than the artifact,
# so the publish job cannot be fooled by a self-consistent replacement of
# the manifest and the tarballs it describes.
- name: Record the prepared manifest digest
id: manifest
shell: bash
run: |
digest="$(sha256sum .release/package-manifest.json | cut -d ' ' -f 1)"
printf 'digest=%s\n' "${digest}" >> "${GITHUB_OUTPUT}"
printf 'Prepared manifest SHA-256 %s\n' "${digest}" >> "${GITHUB_STEP_SUMMARY}"

- name: Upload the prepared release
id: upload
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
Expand All @@ -95,6 +108,7 @@ jobs:
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_COMMIT: ${{ github.sha }}
RELEASE_MANIFEST_DIGEST: ${{ needs.prepare.outputs.manifest-digest }}

steps:
- name: Check out the exact release tag
Expand All @@ -117,4 +131,4 @@ jobs:
path: .release

- name: Publish the verified prepared tarball
run: npm run release:publish -- -- --expected-release-commit "${RELEASE_COMMIT}" --manifest .release/package-manifest.json
run: npm run release:publish -- -- --expected-release-commit "${RELEASE_COMMIT}" --expected-manifest-digest "${RELEASE_MANIFEST_DIGEST}" --manifest .release/package-manifest.json
69 changes: 47 additions & 22 deletions docs/securityscan.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ authorized the caller. Attacker-relevant surfaces:
## Findings

### [MEDIUM] Dev-only dependency chain (azurite) carries 12 known vulnerabilities

✅ Resolved 2026-07-29 — resolved as **contained, not eliminated**. The 12
advisories are still present in the dev-only azurite chain and there is no
upstream fix to take: 3.36.0 is the latest release, and npm's proposed 3.33.0 is
a downgrade that keeps the same vulnerable `rimraf` and pulls _older_ `uuid` and
`@azure/ms-rest-js`. What changed is the boundary: CI now gates on
`npm audit --omit=dev --audit-level=low`, so shipped dependencies are enforced
clean (currently 0 advisories) and any future _runtime_ advisory fails the build,
while the dev-chain advisories remain a tracked, non-gating item to re-check when
azurite next releases.

- **Location:** root `package.json:28` (`"azurite": "^3.36.0"`); full chains in
`npm audit` output (appendix below).
- **Evidence:** 5 high — `brace-expansion` (GHSA-mh99-v99m-4gvg, DoS via
Expand All @@ -122,10 +133,17 @@ authorized the caller. Attacker-relevant surfaces:
- **Fix:** Track an azurite release that drops the vulnerable transitives and
bump the devDependency when available (npm currently proposes azurite
3.33.0 as the "fix", which is a downgrade — verify before applying). Add
`npm audit --omit=dev` (expected clean) to CI so a *runtime* advisory fails
`npm audit --omit=dev` (expected clean) to CI so a _runtime_ advisory fails
the build, and keep dev-chain advisories as a tracked, non-gating item.

### [LOW] Publish pipeline trusts the cross-job artifact's self-consistency

✅ Resolved 2026-07-29 — `prepare` now records the SHA-256 of
`package-manifest.json` as a job output and `publish` passes it to
`release:publish` via `--expected-manifest-digest`, so the manifest is anchored
across the job boundary through run metadata instead of the artifact; the digest
is required and verified with `timingSafeEqual` before the manifest is parsed.

- **Location:** `.github/workflows/publish.yml:74-86, 113-120`;
`scripts/release-packages.mjs:509-560` (`verifyPreparedManifest`).
- **Evidence:** the `publish` job downloads `.release/` (tarballs plus
Expand All @@ -152,30 +170,37 @@ authorized the caller. Attacker-relevant surfaces:

## Phase 3 — Summary

| Severity | Count |
| -------- | ----- |
| Critical | 0 |
| High | 0 |
| Medium | 1 |
| Low | 1 |

| Layer | Status |
| ----- | ------ |
| Frontend | Not present (library repo) |
| Port (`@pegma/storage-blobs`) | Clean — strict validation, copy-on-store, store-bound cursors |
| Adapters (azure-blob, s3, cloudflare-r2) | Clean — credentials host-injected, no env reads, SAS stripped from cursors |
| Data layer | Not present (no query language; opaque object storage) |
| Config & CI | Strong — pinned actions, least-privilege permissions, OIDC trusted publishing, signed-tag enforcement; one Low on artifact handoff |
| Dependencies | Medium — 12 advisories, all confined to the dev-only azurite chain |
Counts below are **as originally scanned on 2026-07-29**, kept as the scan
record. Both findings were subsequently dispositioned — see the per-finding
resolution notes above: the Low (artifact handoff) is fixed outright, and the
Medium (azurite dev chain) is contained by the runtime audit gate with the
dev-only advisories still open upstream.

| Severity | Count | Current state |
| -------- | ----- | ------------------------------------- |
| Critical | 0 | — |
| High | 0 | — |
| Medium | 1 | Contained (dev-only, no upstream fix) |
| Low | 1 | Fixed |

| Layer | Status |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| Frontend | Not present (library repo) |
| Port (`@pegma/storage-blobs`) | Clean — strict validation, copy-on-store, store-bound cursors |
| Adapters (azure-blob, s3, cloudflare-r2) | Clean — credentials host-injected, no env reads, SAS stripped from cursors |
| Data layer | Not present (no query language; opaque object storage) |
| Config & CI | Strong — pinned actions, least-privilege permissions, OIDC trusted publishing, signed-tag enforcement; artifact handoff Low resolved 2026-07-29 |
| Dependencies | Medium — 12 advisories, all confined to the dev-only azurite chain; runtime audit gate added 2026-07-29, shipped dependencies clean |

### Unverified / Needs Manual Review

- **`.tmp-sc/` working-tree scratch copy of storage-core** — untracked and
git-ignored, so it cannot ship, but confirm it is intentional local scratch
and delete if stale.
- **npm audit "fix" for azurite (3.33.0)** — flagged semver-major and is a
version *downgrade*; needs manual verification against the azurite changelog
before applying.
- **`.tmp-sc/` working-tree scratch copy of storage-core** — ✅ Resolved
2026-07-29 — confirmed local-only: neither `.tmp-sc/` nor `.grok/` is tracked,
and both are absent from a fresh clone. Nothing to remove in the repository.
- **npm audit "fix" for azurite (3.33.0)** — ✅ Resolved 2026-07-29 — verified
and rejected. 3.33.0 declares the same vulnerable `rimraf ^3.0.2` plus older
`uuid ^3.3.2` and `@azure/ms-rest-js ^1.5.0`, so the "fix" is a downgrade that
resolves nothing. The devDependency stays at `^3.36.0`.

### Appendix — npm audit (raw, trimmed)

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/storage-azure-blob/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pegma/storage-azure-blob",
"version": "0.1.0",
"version": "0.1.1",
"description": "Azure Blob Storage adapter for @pegma/storage-blobs.",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@azure/storage-blob": "^12.29.1",
"@pegma/storage-blobs": "0.1.0"
"@pegma/storage-blobs": "0.1.1"
},
"scripts": {
"build": "tsc -p tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/storage-blobs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pegma/storage-blobs",
"version": "0.1.0",
"version": "0.1.1",
"description": "Provider-neutral object (blob) storage: opaque keys, streaming put/get, conditionals, and a conformance suite.",
"license": "MIT",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions packages/storage-cloudflare-r2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pegma/storage-cloudflare-r2",
"version": "0.1.0",
"version": "0.1.1",
"description": "Cloudflare R2 adapter for @pegma/storage-blobs (S3-compatible API).",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@aws-sdk/client-s3": "^3.1097.0",
"@pegma/storage-blobs": "0.1.0"
"@pegma/storage-blobs": "0.1.1"
},
"scripts": {
"build": "tsc -p tsconfig.json",
Expand Down
4 changes: 2 additions & 2 deletions packages/storage-s3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pegma/storage-s3",
"version": "0.1.0",
"version": "0.1.1",
"description": "AWS S3 / S3-compatible adapter for @pegma/storage-blobs.",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@aws-sdk/client-s3": "^3.1097.0",
"@pegma/storage-blobs": "0.1.0"
"@pegma/storage-blobs": "0.1.1"
},
"scripts": {
"build": "tsc -p tsconfig.json",
Expand Down
16 changes: 13 additions & 3 deletions scripts/release-packages.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ValidationOptions {
export interface ReleaseCommandOptions extends ValidationOptions {
readonly manifest?: string;
readonly output?: string;
readonly expectedManifestDigest?: string;
}

export interface PublicPackageManifest {
Expand Down Expand Up @@ -52,9 +53,18 @@ export function decidePublication(
registryIntegrity: string | null,
): "publish" | "skip";

export function prepareRelease(
options?: ReleaseCommandOptions,
): Promise<{ manifestPath: string; manifest: unknown }>;
export function digestManifest(bytes: Uint8Array | string): string;

export function verifyManifestDigest(
bytes: Uint8Array | string,
expectedDigest: string | undefined,
): string;

export function prepareRelease(options?: ReleaseCommandOptions): Promise<{
manifestPath: string;
manifest: unknown;
manifestDigest: string;
}>;

export function publishPreparedRelease(
options?: ReleaseCommandOptions,
Expand Down
56 changes: 49 additions & 7 deletions scripts/release-packages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ function hashTarball(bytes) {
};
}

export function digestManifest(bytes) {
return createHash("sha256").update(bytes).digest("hex");
}

// The prepared manifest travels to the publish job inside the same artifact as
// the tarballs it describes, so a self-consistent replacement of both would
// satisfy every internal check. The preparation job therefore reports the
// manifest digest as a job output, which crosses the boundary through run
// metadata instead of the artifact, and publication refuses to proceed without
// a match.
export function verifyManifestDigest(bytes, expectedDigest) {
if (expectedDigest === undefined || expectedDigest === "") {
fail("an expected prepared manifest digest is required");
}
if (!/^[0-9a-f]{64}$/u.test(expectedDigest)) {
fail("the expected prepared manifest digest must be SHA-256 hexadecimal");
}
const actualDigest = digestManifest(bytes);
if (!safeEqual(actualDigest, expectedDigest)) {
fail(
"the prepared package manifest does not match the digest recorded by the preparation job",
);
}
return actualDigest;
}

function exportTargets(value) {
if (typeof value === "string") return [value];
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
Expand Down Expand Up @@ -449,8 +475,16 @@ export async function prepareRelease(options = {}) {
packages: preparedPackages,
};
const manifestPath = join(output, "package-manifest.json");
await writeFile(manifestPath, `${JSON.stringify(prepared, null, 2)}\n`);
return { manifestPath, manifest: prepared };
const manifestBytes = Buffer.from(
`${JSON.stringify(prepared, null, 2)}\n`,
"utf8",
);
await writeFile(manifestPath, manifestBytes);
return {
manifestPath,
manifest: prepared,
manifestDigest: digestManifest(manifestBytes),
};
}

function queryRegistryIntegrity(name, version) {
Expand Down Expand Up @@ -506,8 +540,10 @@ function confirmRegistryIntegrity(record) {
);
}

async function verifyPreparedManifest(path) {
const prepared = await readJson(path);
async function verifyPreparedManifest(path, expectedManifestDigest) {
const manifestBytes = await readFile(path);
verifyManifestDigest(manifestBytes, expectedManifestDigest);
const prepared = JSON.parse(manifestBytes.toString("utf8"));
const records = prepared.packages;
if (
prepared.schemaVersion !== 2 ||
Expand Down Expand Up @@ -568,7 +604,10 @@ export async function publishPreparedRelease(options = {}) {
}
requireTrustedPublishingNpm();
const path = resolve(options.manifest ?? ".release/package-manifest.json");
const prepared = await verifyPreparedManifest(path);
const prepared = await verifyPreparedManifest(
path,
options.expectedManifestDigest ?? process.env.RELEASE_MANIFEST_DIGEST,
);
const releaseTag = options.releaseTag ?? process.env.RELEASE_TAG;
const expectedCommit =
options.expectedReleaseCommit ?? process.env.RELEASE_COMMIT;
Expand Down Expand Up @@ -634,7 +673,9 @@ export function parseArguments(arguments_) {
? "manifest"
: argument === "--expected-release-commit"
? "expectedReleaseCommit"
: null;
: argument === "--expected-manifest-digest"
? "expectedManifestDigest"
: null;
if (key === null || arguments_[index + 1] === undefined) {
fail(`unknown or incomplete argument: ${argument}`);
}
Expand All @@ -657,8 +698,9 @@ async function main() {
return;
}
if (command === "pack") {
const { manifestPath } = await prepareRelease(options);
const { manifestPath, manifestDigest } = await prepareRelease(options);
process.stdout.write(`Prepared release package at ${manifestPath}.\n`);
process.stdout.write(`Prepared manifest SHA-256 ${manifestDigest}.\n`);
return;
}
if (command === "publish") {
Expand Down
Loading
Loading