Skip to content

ci(security): skip Snyk job when SNYK_TOKEN is unavailable (fixes Dependabot/fork PR failures)#102

Closed
NeuroKoder3 wants to merge 2 commits intomainfrom
ci/fix-snyk-skip-when-no-token
Closed

ci(security): skip Snyk job when SNYK_TOKEN is unavailable (fixes Dependabot/fork PR failures)#102
NeuroKoder3 wants to merge 2 commits intomainfrom
ci/fix-snyk-skip-when-no-token

Conversation

@NeuroKoder3
Copy link
Copy Markdown
Owner

Summary

Both open Dependabot PRs (#100 and #101) — and any future Dependabot PR or fork PR — were failing the Security Scanning workflow at the Snyk step with 401 Unauthorized because GitHub does not expose regular Actions secrets to Dependabot. secrets.SNYK_TOKEN resolves to an empty string in those contexts, Snyk auth fails, the job fails, and the PR check is red.

This PR makes the Snyk job skip gracefully when SNYK_TOKEN is unavailable, with a companion snyk-skipped-notice job that explains in the run summary why Snyk was skipped and confirms what coverage remains.

What's still covered when Snyk skips

  • The audit job (in this same workflow) runs npm audit --omit=dev --audit-level=moderate — fails the workflow on any moderate+ production dependency vulnerability.
  • The CodeQL Analysis workflow (separate file) runs and is independent of SNYK_TOKEN.
  • Dependabot itself raises alerts and PRs for vulnerable dependencies independently of the workflow.

What this does NOT change

  • On the main branch (and on every PR opened from a branch in this repo by a maintainer), if SNYK_TOKEN is set in the regular Actions secrets, Snyk runs exactly as before.
  • The audit job is unchanged and still mandatory.

How to enable Snyk on Dependabot PRs in the future

Add SNYK_TOKEN as a Dependabot secret, not an Actions secret:

Settings → Secrets and variables → Dependabot → New repository secret

Adding it under Actions does not work for Dependabot PRs — that's a deliberate GitHub design.

Test plan

  • YAML parses cleanly with js-yaml (verified locally).
  • Job structure: audit, snyk, snyk-skipped-notice, lint, test-security, load-test, lockfile-check, report-audit-status.
  • When SNYK_TOKEN is empty (Dependabot/fork PR/unconfigured repo), snyk is skipped and snyk-skipped-notice runs and posts an informational notice.
  • When SNYK_TOKEN is non-empty (maintainer PR with the secret configured), snyk runs as before and snyk-skipped-notice is skipped.
  • Verify the workflow on this PR shows the snyk job as skipped (not failed) and the notice job as green.

Cross-references

NeuroKoder3 and others added 2 commits May 9, 2026 23:31
Every Dependabot PR (and every fork PR) was failing the Security
Scanning workflow at the Snyk step with `401 Unauthorized` because
GitHub does not expose regular repo Actions secrets to Dependabot —
Dependabot has its own separate secret namespace, so
`secrets.SNYK_TOKEN` resolves to an empty string and Snyk auth fails.

Fix: gate the snyk job on `secrets.SNYK_TOKEN != ''` so it skips
gracefully whenever the token is unavailable. Add a companion
`snyk-skipped-notice` job that explains in the run summary why Snyk
was skipped and confirms that dependency-vulnerability coverage is
still provided on the PR by:

  - the audit job (npm audit, in this same workflow)
  - the CodeQL Analysis workflow (separate file)

This permanently unblocks Dependabot PRs and fork PRs without losing
any dependency-security signal that was actually being produced.

To enable Snyk on Dependabot PRs in the future, add SNYK_TOKEN at:
  Settings → Secrets and variables → Dependabot → New repository secret

(Adding it to the regular Actions secrets does not work for Dependabot
PRs by design.)

Co-authored-by: Cursor <cursoragent@cursor.com>
…lidation fix)

Previous attempt at this fix used `secrets.SNYK_TOKEN` in a job-level
`if:` condition. GitHub Actions rejected the workflow at parse time
("This run likely failed because of a workflow file issue", 0-second
runtime, no jobs started) because referencing the `secrets` context
inside a job-level `if:` is not supported in the same way it is at the
step level.

Refactor:

- Job-level `if:` reverts to the original simple expression
  (`github.event_name != 'schedule'`).
- A new first step in the `snyk` job exposes `SNYK_TOKEN` via the `env:`
  block (the documented-safe way to read a secret) and writes a
  `has_token=true|false` value to `$GITHUB_OUTPUT`.
- All subsequent steps (setup-node, npm ci, Snyk action) gate on
  `steps.snyk_token.outputs.has_token == 'true'`.
- When the token is absent, the step emits a GitHub Actions notice
  (`::notice title=Snyk skipped::...`) explaining why and confirming
  what coverage remains (npm audit + CodeQL).
- The auxiliary `snyk-skipped-notice` job is removed; the notice is
  now emitted from inside the snyk job itself.

Net behaviour for the consumer (Dependabot PRs, fork PRs, repos with
no Snyk token):

- Snyk job runs to completion in seconds, posts a clear "skipped"
  notice, and is reported as PASS instead of FAIL.
- The `audit` job (npm audit) is unchanged and continues to gate
  the workflow on production-dependency vulnerabilities.

Validated locally with `js-yaml` (parses cleanly, 7 jobs, snyk job has
5 steps, no `secrets` reference at job level).

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant