Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-js): pin the npm used by the trusted-publishing job
Yudhi Armyndharis1ef21ee69389
diff --git a/.github/workflows/js-sdk-release.yml b/.github/workflows/js-sdk-release.ymlindex 7f205f122..a03f58a81 100644--- a/.github/workflows/js-sdk-release.yml+++ b/.github/workflows/js-sdk-release.yml@@ -76,9 +76,11 @@ jobs:- name: Use an npm that supports trusted publishing# The npm bundled with Node 22 predates OIDC publishing (needs >= 11.5.1), and it fails by- # looking for a token rather than by naming the missing support — so pin the requirement here.+ # looking for a token rather than by naming the missing support. Pinned to the exact release+ # the Dockerfile uses: this npm runs while the job can mint a publish credential, so it must+ # not float to whatever version is current when the tag is pushed.run: |- npm install -g npm@latest+ npm install -g [email protected]npm --version- run: npm cidiff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.tsindex 5e2ce16fb..032c1b9dc 100644--- a/src/common/ci-privilege-gate.spec.ts+++ b/src/common/ci-privilege-gate.spec.ts@@ -137,3 +137,45 @@ describe('a job that runs a repo script checks the repo out', () => {expect(offenders).toEqual([]);});});++/**+ * A job granted `id-token: write` can mint a registry publish credential, so every tool it installs+ * globally runs with that ability. A floating spec (`npm@latest`, a bare major) resolves to whatever+ * was published most recently at tag time; pin the exact version the way the Dockerfile pins its npm.+ */+describe('a job that can mint a publish credential installs only exact global versions', () => {+ type OidcJob = { permissions?: Record<string, string> | string; steps?: Step[] };+ const workflows = fs.readdirSync(workflowDir).filter(f => f.endsWith('.yml') || f.endsWith('.yaml'));+ const GLOBAL_INSTALL = /\bnpm\s+(?:install|i|add)\s+(?:-g|--global)\s+([^\n;&|]+)/g;++ const globalInstallsInOidcJobs = (file: string): Array<{ job: string; spec: string }> => {+ const jobs = (+ yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as { jobs?: Record<string, OidcJob> }+ ).jobs;+ return Object.entries(jobs ?? {})+ .filter(([, def]) => typeof def.permissions === 'object' && def.permissions['id-token'] === 'write')+ .flatMap(([job, def]) =>+ (def.steps ?? []).flatMap(step =>+ [...executableLines(step.run ?? '').matchAll(GLOBAL_INSTALL)].flatMap(match =>+ match[1]+ .trim()+ .split(/\s+/)+ .filter(arg => !arg.startsWith('-'))+ .map(spec => ({ job, spec })),+ ),+ ),+ );+ };++ // Non-vacuity: the JS SDK release job installs its own npm, so the finder must see it.+ it('finds the global npm install in the JS SDK publish job', () => {+ expect(globalInstallsInOidcJobs('js-sdk-release.yml').map(entry => entry.spec)).toEqual([+ expect.stringMatching(/^npm@/),+ ]);+ });++ it.each(workflows)('%s: global installs in id-token jobs are pinned to an exact version', file => {+ const floating = globalInstallsInOidcJobs(file).filter(entry => !/@\d+\.\d+\.\d+$/.test(entry.spec));+ expect(floating).toEqual([]);+ });+});