OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
ci: share the exact npm setup for release workflows (#1998)
Michael D'Angeloa828e0ab7292
diff --git a/.github/scripts/release-npm.sh b/.github/scripts/release-npm.shnew file mode 100644index 000000000..4fc597dc9--- /dev/null+++ b/.github/scripts/release-npm.sh@@ -0,0 +1,17 @@+#!/usr/bin/env bash+release_npm_version=11.12.1+release_npm_prefix="$RUNNER_TEMP/codex-security-provenance-npm"+release_npm_bin="$release_npm_prefix/node_modules/.bin"++verify_release_npm() {+ if [[ "$1" != "$release_npm_bin/npm" || "$("$1" --version)" != "$release_npm_version" ]]; then+ echo "Expected npm $release_npm_version at $release_npm_bin/npm for provenance verification." >&2+ return 1+ fi+}++install_release_npm() {+ npm install --prefix "$release_npm_prefix" --ignore-scripts --no-audit --no-fund \+ --registry=https://openai.firewall.socket.dev/npm/ "npm@$release_npm_version"+ verify_release_npm "$release_npm_bin/npm"+}diff --git a/.github/workflows/node-github-release.yml b/.github/workflows/node-github-release.ymlindex a0fd2cbc3..19e183dad 100644--- a/.github/workflows/node-github-release.yml+++ b/.github/workflows/node-github-release.yml@@ -56,29 +56,16 @@ jobs:shell: bashrun: |set -euo pipefail- npm_tools="$RUNNER_TEMP/codex-security-provenance-npm"- npm install \- --prefix "$npm_tools" \- --ignore-scripts \- --no-audit \- --no-fund \- --registry=https://openai.firewall.socket.dev/npm/ \+ source .github/scripts/release-npm.sh+ install_release_npm+ printf '%s\n' "$release_npm_bin" >> "$GITHUB_PATH"- if [[ "$("$npm_tools/node_modules/.bin/npm" --version)" != "11.12.1" ]]; then- echo "npm 11.12.1 is required to verify Sigstore attestations." >&2- exit 1- fi- printf '%s\n' "$npm_tools/node_modules/.bin" >> "$GITHUB_PATH"-- - name: Verify bundled provenance-capable npm+ - name: Verify npm on PATHshell: bashrun: |set -euo pipefail- if [[ "$(npm --version)" != "11.12.1" ]]; then- echo "npm 11.12.1 is required to verify Sigstore attestations." >&2- exit 1- fi+ source .github/scripts/release-npm.sh+ verify_release_npm "$(command -v npm)"- name: Resolve the successful protected releaseid: releasediff --git a/.github/workflows/node-release.yml b/.github/workflows/node-release.ymlindex e9d8d3272..67ecd41ba 100644--- a/.github/workflows/node-release.yml+++ b/.github/workflows/node-release.yml@@ -329,42 +329,16 @@ jobs:shell: bashrun: |set -euo pipefail- npm_tools="$RUNNER_TEMP/codex-security-provenance-npm"- npm install \- --prefix "$npm_tools" \- --ignore-scripts \- --no-audit \- --no-fund \- --registry=https://openai.firewall.socket.dev/npm/ \-- if [[ "$("$npm_tools/node_modules/.bin/npm" --version)" != "11.12.1" ]]; then- echo "npm 11.12.1 is required to verify Sigstore attestations." >&2- exit 1- fi- printf '%s\n' "$npm_tools/node_modules/.bin" >> "$GITHUB_PATH"+ source .github/scripts/release-npm.sh+ install_release_npm+ printf '%s\n' "$release_npm_bin" >> "$GITHUB_PATH"- - name: Verify bundled trusted-publishing npm+ - name: Verify npm on PATHshell: bashrun: |set -euo pipefail- node --eval '- const version = process.argv[1];- const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);- const [major, minor, patch] = match?.slice(1).map(Number) ?? [];- if (- !match ||- major < 11 ||- (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))- ) {- console.error(- "npm 11.5.1 or newer is required for trusted publishing; found " +- version +- ".",- );- process.exit(1);- }- ' "$(npm --version)"+ source .github/scripts/release-npm.sh+ verify_release_npm "$(command -v npm)"- name: Download verified packageuses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2diff --git a/.github/workflows/workflow-quality.yml b/.github/workflows/workflow-quality.ymlindex d46aa9b42..4f71c49c4 100644--- a/.github/workflows/workflow-quality.yml+++ b/.github/workflows/workflow-quality.yml@@ -38,7 +38,7 @@ jobs:SHELLCHECK_OPTS: --severity=warningrun: |actionlint -color- shellcheck .github/scripts/install-ripgrep.sh docker/verify-container-compose.sh github-action/scripts/setup-ubuntu-sandbox.sh+ shellcheck .github/scripts/*.sh docker/verify-container-compose.sh github-action/scripts/setup-ubuntu-sandbox.sh- name: Test release progress reportingrun: node --test .github/scripts/test_release_progress.mjs- name: Check workflow securitydiff --git a/sdk/typescript/tests-ts/release-automation.test.ts b/sdk/typescript/tests-ts/release-automation.test.tsindex 1c83f7bac..e68172f0c 100644--- a/sdk/typescript/tests-ts/release-automation.test.ts+++ b/sdk/typescript/tests-ts/release-automation.test.ts@@ -3815,24 +3815,43 @@ ${workflowStepShell(releaseCutWorkflow, "Resolve the stable package version")}test("cryptographically verifies the exact npm provenance bundle", () => {expect(githubReleaseWorkflow).toContain('node-version: "24.15.0"');- expect(githubReleaseWorkflow).toContain(- 'if [[ "$(npm --version)" != "11.12.1" ]]; then',- );expect(githubReleaseWorkflow).toContain("npm audit signatures");expect(githubReleaseWorkflow).toContain("--include-attestations");expect(githubReleaseWorkflow).toContain("verify-recovered-provenance");});- test("installs the exact attestation-capable npm through the Socket Firewall", () => {- for (const workflow of [githubReleaseWorkflow, protectedReleaseWorkflow]) {- expect(workflow).toContain("Install provenance-capable npm");- expect(workflow).toContain("[email protected]");- expect(workflow).toContain(- "--registry=https://openai.firewall.socket.dev/npm/",- );- expect(workflow).toContain('>> "$GITHUB_PATH"');- expect(workflow).not.toContain("npm install --global");- }+ test("both release jobs require the npm installed through the Socket Firewall", async () => {+ const both = (name: string) => {+ const script = workflowStepShell(protectedReleaseWorkflow, name);+ expect(workflowStepShell(githubReleaseWorkflow, name)).toBe(script);+ return script;+ };+ const result = await runShell(+ `RUNNER_TEMP="$(cd "$RUNNER_TEMP" && pwd)"+GITHUB_PATH="$RUNNER_TEMP/path"+npm() {+ printf '<%s>' "$1" "$2" "\${3#"$RUNNER_TEMP/"}" "\${@:4}"+ mkdir -p "$3/node_modules/.bin"+ printf '#!/bin/sh\\necho "\${TEST_NPM_VERSION:-11.12.1}"\\n' > "$3/node_modules/.bin/npm"+ chmod +x "$3/node_modules/.bin/npm"+}+${both("Install provenance-capable npm")}+export PATH="$(cat "$GITHUB_PATH"):$PATH"+verify() { "$BASH" <<'VERIFY'+${both("Verify npm on PATH")}+VERIFY+}+verify && echo selected+TEST_NPM_VERSION=11.10.1 verify && exit 2+cp "$release_npm_bin/npm" "$RUNNER_TEMP/npm"+PATH="$RUNNER_TEMP:$PATH" verify`,+ { RUNNER_TEMP: directories.create("release npm ") },+ { cwd: fileURLToPath(new URL("../../../", import.meta.url)) },+ );+ expect(result.stdout).toBe(+ "<install><--prefix><codex-security-provenance-npm><--ignore-scripts><--no-audit><--no-fund><--registry=https://openai.firewall.socket.dev/npm/><[email protected]>selected\n",+ );+ expect(result.status, result.stderr).toBe(1);});test("serializes label reconciliation and reads the current PR title", () => {