Add CI, strengthen verification logic, raw-body checks, QStash loading, and test harness#45
Conversation
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Build | ||
| run: npm run build | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Test | ||
| run: npm test |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
In general, the fix is to explicitly add a permissions block to the workflow (or individual jobs) to limit the GITHUB_TOKEN to the least privileges necessary. For a standard CI pipeline that only checks out code and runs build/test/lint locally, contents: read is typically sufficient. Defining permissions at the top level applies them to all jobs unless overridden.
For this specific file, the best fix without changing behavior is to add a root-level permissions block after the workflow name: and before the on: section:
name: CI
permissions:
contents: readThis leaves all existing steps unchanged while ensuring the GITHUB_TOKEN is restricted to read-only access to repository contents, which is enough for actions/checkout and the subsequent commands. No imports, methods, or additional definitions are needed.
| @@ -1,11 +1,12 @@ | ||
| name: CI | ||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| quality: | ||
| runs-on: ubuntu-latest |
Motivation
main.Description
CIthat runsnpm ci,npm run build,npm run lint, andnpm teston PRs and pushes tomain.package.jsonto run the TypeScript test harness viats-nodeusingnpm testand added an.npmignoreto exclude compiled test artifacts from packages.strictRawBodyoption (defaulttrue) and a check using a new helper to reject parsed JSON bodies early with a 400 response and guidance to useexpress.raw.hasParsedBodyand updatedextractRawBodyto.warn and handle already-parsed JSON bodies consistently.src/index.ts): parallelizedverifyAnyacross provided secrets and aggregate diagnostics, added a timing-safesafeCompareusing Node'stimingSafeEqual, and switched token comparison inverifyTokenAuthto use the safe comparator; also small metadata key access fix for Sanity payloads.src/upstash/queue.ts): made dynamic module loading robust by using nativeimport(...), added typed constructor resolution forReceiver/Client, improved export resolution to support different package shapes, and minor header destructuring fixes.src/verifiers/algorithms.ts): addedrequiresTimestamplogic to enforce timestamp presence when needed, tightenedfal.aitimestamp handling, added fetch timeout for JWKS retrieval, and cleaned up public key resolution for ED25519 verifications.src/test.ts): improved signature helpers, added atrackCheckcollector to aggregate failing checks and cause a non-zero exit when failures occur, improved logging and process exit handling, and adjusted a number of test expectations to match verification changes.tsconfig.json): formattedlibentries and added exclusions for test files so they are not included in published builds.Testing
.github/workflows/ci.yml) to runnpm ci,npm run build,npm run lint, andnpm testfor PRs and pushes tomain(automated pipeline added but not yet observed in this PR run).npm run build(TypeScript compile) which completed successfully.npm test(ts-node src/test.ts) which executed the verification checks; the harness aggregates failures and returns non-zero on failure and the local run completed successfully.Codex Task