Skip to content

fix(api): gate /alerts/ingest on alerts:ingest API key scope - #4208

Merged
dipexplorer merged 1 commit into
RatLoopz:mainfrom
Kirtan-pc:fix/4199-api-key-scope-gate-on-alerts-ingest
Aug 8, 2026
Merged

fix(api): gate /alerts/ingest on alerts:ingest API key scope#4208
dipexplorer merged 1 commit into
RatLoopz:mainfrom
Kirtan-pc:fix/4199-api-key-scope-gate-on-alerts-ingest

Conversation

@Kirtan-pc

Copy link
Copy Markdown
Contributor

🛑 STOP: Assignment & File Scope Check

  • I am assigned to this issue.
  • I verified that this PR ONLY touches the required files.

Warning

PRs with unrelated files will not be reviewed and may be closed.

📋 PR Summary & Link

  • Closes [BUG] API-key scopes are never enforced , any key holder can trigger the global alert-ingest write path #4199
  • Summary:
    The POST /api/v1/alerts/ingest route was protected only by requireApiKey, but the scopes the middleware loaded into req.apiKey.scopes were never consulted. Any valid key — including narrowly-scoped read-only keys — had the same privilege as the intended moderation credential, enabling attackers to reclassify medicines as recalled and mass-broadcast fake recall alerts.
    Changes:
    apps/api/src/middleware/apiKeyAuth.ts — added requireApiKeyScope(scope) middleware that returns 403 when req.apiKey.scopes lacks the required scope.
    apps/api/src/routes/alerts.ts:194-199 — applied requireApiKeyScope("alerts:ingest") to the /ingest route.
    apps/api/tests/alertsPagination.test.ts — added a test asserting a valid key lacking the scope gets 403 (20/20 tests pass).

🏷️ PR Type

  • 🐛 type: bug
  • type: feature
  • 📖 type: docs
  • 🧪 type: testing
  • 🔒 type: security
  • type: performance
  • 🎨 type: design
  • ♻️ type: refactor
  • 🛠️ type: devops
  • type: accessibility

✅ Checklist

  • My PR has a linked issue (Closes #4199)
  • I have pulled the latest main and resolved any conflicts

API keys carry scopes but no route ever consulted them, so any valid key
(including narrowly-scoped read-only keys) could invoke POST /alerts/ingest
and reclassify medicines as recalled while mass-broadcasting fake recall
alerts to patients.

Add requireApiKeyScope(scope) middleware and require alerts:ingest on the
ingest route. Keys lacking the scope now receive 403 before acting.
@github-project-automation github-project-automation Bot moved this to 📥 Backlog in SahiDawa Workflow Aug 7, 2026
@github-actions github-actions Bot added gssoc:approved Approved for gssoc type:bug Something isn't working type:security Auth, rate limiting, security labels Aug 7, 2026
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@dipexplorer dipexplorer added level:critical 80 pts quality:clean multiplier x1.2 type:refactor Code structure cleanup without behavior change labels Aug 8, 2026
@dipexplorer
dipexplorer merged commit e47bfaf into RatLoopz:main Aug 8, 2026
22 of 27 checks passed
@github-project-automation github-project-automation Bot moved this from 📥 Backlog to 🎉 Merged in SahiDawa Workflow Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for gssoc level:critical 80 pts quality:clean multiplier x1.2 type:bug Something isn't working type:refactor Code structure cleanup without behavior change type:security Auth, rate limiting, security

Projects

Status: 🎉 Merged

Development

Successfully merging this pull request may close these issues.

[BUG] API-key scopes are never enforced , any key holder can trigger the global alert-ingest write path

2 participants