Skip to content

Add CI, strengthen verification logic, raw-body checks, QStash loading, and test harness#45

Merged
Prateek32177 merged 2 commits intomainfrom
codex/conduct-security-audit-for-tern-sdk
Feb 28, 2026
Merged

Add CI, strengthen verification logic, raw-body checks, QStash loading, and test harness#45
Prateek32177 merged 2 commits intomainfrom
codex/conduct-security-audit-for-tern-sdk

Conversation

@Prateek32177
Copy link
Contributor

Motivation

  • Add continuous integration and tighten developer tooling to ensure builds, linting and tests run on PRs and pushes to main.
  • Harden webhook verification around timing-safe string comparisons and parallel multi-platform verification to improve security and diagnostics.
  • Prevent mis-configuration when Express has already parsed request bodies and make Upstash QStash integration more resilient across package shapes.
  • Improve the local test harness and TypeScript configuration to exclude test artifacts from builds.

Description

  • Added a GitHub Actions workflow CI that runs npm ci, npm run build, npm run lint, and npm test on PRs and pushes to main.
  • Modified package.json to run the TypeScript test harness via ts-node using npm test and added an .npmignore to exclude compiled test artifacts from packages.
  • Express adapter changes: added strictRawBody option (default true) and a check using a new helper to reject parsed JSON bodies early with a 400 response and guidance to use express.raw.
  • Shared adapter changes: introduced hasParsedBody and updated extractRawBody to.warn and handle already-parsed JSON bodies consistently.
  • Verification core (src/index.ts): parallelized verifyAny across provided secrets and aggregate diagnostics, added a timing-safe safeCompare using Node's timingSafeEqual, and switched token comparison in verifyTokenAuth to use the safe comparator; also small metadata key access fix for Sanity payloads.
  • Upstash queue (src/upstash/queue.ts): made dynamic module loading robust by using native import(...), added typed constructor resolution for Receiver/Client, improved export resolution to support different package shapes, and minor header destructuring fixes.
  • Verifiers (src/verifiers/algorithms.ts): added requiresTimestamp logic to enforce timestamp presence when needed, tightened fal.ai timestamp handling, added fetch timeout for JWKS retrieval, and cleaned up public key resolution for ED25519 verifications.
  • Test harness (src/test.ts): improved signature helpers, added a trackCheck collector 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.
  • TypeScript config (tsconfig.json): formatted lib entries and added exclusions for test files so they are not included in published builds.

Testing

  • Added CI workflow (.github/workflows/ci.yml) to run npm ci, npm run build, npm run lint, and npm test for PRs and pushes to main (automated pipeline added but not yet observed in this PR run).
  • Locally executed npm run build (TypeScript compile) which completed successfully.
  • Ran the test harness via 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

Comment on lines +11 to +32
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

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

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: read

This 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.

Suggested changeset 1
.github/workflows/ci.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,11 +1,12 @@
 name: CI
+permissions:
+  contents: read
 
 on:
   pull_request:
   push:
     branches:
       - main
-
 jobs:
   quality:
     runs-on: ubuntu-latest
EOF
@@ -1,11 +1,12 @@
name: CI
permissions:
contents: read

on:
pull_request:
push:
branches:
- main

jobs:
quality:
runs-on: ubuntu-latest
Copilot is powered by AI and may make mistakes. Always verify output.
@Prateek32177 Prateek32177 merged commit 1334455 into main Feb 28, 2026
4 checks passed
@Prateek32177 Prateek32177 deleted the codex/conduct-security-audit-for-tern-sdk branch February 28, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant