fix(security): scope glob and minimatch overrides to affected parents

This commit is contained in:
victorsteele428 committed 2026-11-22 14:33:36 +00:00
1 parent 43eee54e7a
commit 66cfed5a8b
25 files changed
+331 -138

No files matched your search

+1
View File
@@ -12,3 +12,4 @@
| [backend_acceptance.sh](backend_acceptance.sh) | Backend-only runner preflight, four-service health, Postgres restart marker and OIDC/JWKS CI checks | P05-CI-03 |
| [backend_cleanup.sh](backend_cleanup.sh) | Always-run cleanup of marked CI-owned Compose project/volumes, with leftover verification | P05-CI-03 |
| [security_advisory_gate.py](security_advisory_gate.py) | Strict CI registry JSON gate: rejects incomplete reports and any Moderate/High/Critical finding | P05-SEC-01 |
| [transitive_override_contract.py](transitive_override_contract.py) | Verify exact seven parent-scoped patched PNPM overrides and no known vulnerable resolved lock entries | P05-SEC-02 |
+2
View File
@@ -16,4 +16,6 @@ No real credentials or production domains are used. Never print bootstrap PATs,
- `security_advisory_gate.py` (P05-SEC-01) takes npm or pnpm registry audit JSON, rejects missing/errored/inconsistent metadata and requires **zero Moderate/High/Critical findings**. It is independent of the existing HIGH+ audit command and `advisory_triage.py` detailed advisory ID report. **Gitea Run #87** proved Account audit 0 and Login audit **2 Moderate** (`glob`, `minimatch`); strict Login gate correctly FAILED. Dedicated `.gitea/workflows/p05-security-acceptance.yml` is manual only; frozen installs/builds are CI-only and passed 1219/1219 Login unit regressions.
- `transitive_override_contract.py` (P05-SEC-02) validates exactly seven parent-scoped PNPM override selectors, absence of known advisory-affected glob/minimatch lock entries, preserved importer structure and each exact patched parent resolution. This is **source-only** and not a live security audit; still require strict Gitea registry `security_advisory_gate.py`, frozen pnpm install, Nx production build and unit suite. Trigger the existing Gitea security workflow with manual `login_only=true`; Account build/security jobs should be skipped.
Add new CI checks and update `MINIFEST.md`, `project/`, `docs/`, and `notes/` in the same approved phase.
+95
View File
@@ -0,0 +1,95 @@
"""P05-SEC-02: read-only PNPM targeted override and locked-resolutions contract.
Invoked in Gitea CI before frozen install. Deliberately no application execution
and no allowance for global/broad major-version overrides.
"""
from __future__ import annotations
from pathlib import Path
import re
import sys
ROOT = Path(__file__).resolve().parents[2]
WORKSPACE = ROOT / "auth/ui/v2"
GLOB_VERSION = "14.0.6"
MINIMATCH_VERSION = "11.0.9"
EXPECTED = {
"rimraf@5.0.10>glob": GLOB_VERSION,
"archiver-utils@5.0.2>glob": GLOB_VERSION,
"@eslint/config-array@0.23.5>minimatch": MINIMATCH_VERSION,
"@typescript-eslint/typescript-estree@8.67.0>minimatch": MINIMATCH_VERSION,
"eslint@10.8.1>minimatch": MINIMATCH_VERSION,
"nodemon@3.1.14>minimatch": MINIMATCH_VERSION,
"nx@22.7.12>minimatch": MINIMATCH_VERSION,
}
def overridden(data: str) -> dict[str, str]:
found: dict[str, str] = {}
for line in data.splitlines():
match = re.match(r"^ ['\"]?([^'\"#][^:]*>[^:'\"]+)['\"]?: ['\"]?([^'\" #]+)", line)
if match:
found[match.group(1)] = match.group(2).rstrip("'\":")
return found
def main() -> None:
work = (WORKSPACE / "pnpm-workspace.yaml").read_text(encoding="utf-8")
lock = (WORKSPACE / "pnpm-lock.yaml").read_text(encoding="utf-8")
if "lockfileVersion: '9.0'" not in lock:
raise AssertionError("Unexpected pnpm lock format")
if not lock.startswith("lockfileVersion:"):
raise AssertionError("Unexpected lock header")
before, after = lock.split("\nimporters:\n", 1)
expected = EXPECTED
found_workspace = overridden(work)
found_lock = overridden(before)
if found_workspace != expected:
raise AssertionError(f"Unexpected workspace parent-scoped overrides: {found_workspace!r}")
if found_lock != expected:
raise AssertionError(f"Lock and source override selectors diverged: {found_lock!r}")
if " - apps/login\n" not in work:
raise AssertionError("Official Login importer removed")
for part in (" apps/login:", " packages/zitadel-client:", " packages/zitadel-proto:"):
if part not in after:
raise AssertionError(f"Required importer missing: {part}")
# The package + snapshot registry sections (not arbitrary free text) must
# have no glob >=9 <=14.0.1 or minimatch >=7 <11.0.1.
for line in lock.splitlines():
m = re.match(r"^ ['\"]?(glob|minimatch)@([0-9]+)\.([0-9]+)\.([0-9]+)(?:['\"]?[:(]|:)", line)
if not m:
continue
name = m.group(1)
version = tuple(int(m.group(i)) for i in range(2, 5))
if name == "glob" and (9, 0, 0) <= version <= (14, 0, 1):
raise AssertionError(f"Vulnerable glob lock entry: {line.strip()}")
if name == "minimatch" and (7, 0, 0) <= version < (11, 0, 1):
raise AssertionError(f"Vulnerable minimatch lock entry: {line.strip()}")
if " glob@14.0.6:" not in lock or " minimatch@11.0.9:" not in lock:
raise AssertionError("Patched glob/minimatch snapshot not present")
snapshots = lock.split("\nsnapshots:\n", 1)[1]
refs: dict[str, list[tuple[str, str]]] = {}
for block in re.split(r"(?m)^ (?=\S)", snapshots):
header = block.splitlines()[0].rstrip(":").strip().strip("'")
for ln in block.splitlines():
m = re.match(r"^ (glob|minimatch): ([0-9]+\.[0-9]+\.[0-9]+)", ln)
if m:
refs.setdefault(header, []).append((m.group(1), m.group(2)))
for selector, version in expected.items():
parent, name = selector.rsplit(">", 1)
matches = [refs[key] for key in refs if key == parent or key.startswith(parent + "(")]
if len(matches) != 1 or (name, version) not in matches[0]:
raise AssertionError(f"Parent {parent} does not resolve exact {name}@{version}")
print("ZITPLANE_EXACT_SEVEN_PARENT_OVERRIDES_PASS")
print("ZITPLANE_GLOB_MINIMATCH_PATCHED_LOCK_CONTRACT_PASS")
if __name__ == "__main__":
try:
main()
except (AssertionError, ValueError, FileNotFoundError, IndexError) as exc:
print(f"ZITPLANE_TRANSITIVE_OVERRIDE_CONTRACT_FAIL: {exc}", file=sys.stderr)
raise SystemExit(1)