Skip to content

feat: security header sweep for /api/me/devices (#594) - #723

Merged
greatest0fallt1me merged 3 commits into
Predictify-org:mainfrom
thelmaoffiong:feature/security-header-devices-594
Jul 29, 2026
Merged

feat: security header sweep for /api/me/devices (#594)#723
greatest0fallt1me merged 3 commits into
Predictify-org:mainfrom
thelmaoffiong:feature/security-header-devices-594

Conversation

@thelmaoffiong

Copy link
Copy Markdown
Contributor

Summary

Implements the security header sweep for /api/me/devices and /api/me/devices/:id/revoke as required by issue #594.

Changes

src/routes/devices.ts

  • Imported securityHeaders from ../middleware/securityHeaders
  • Mounted devicesRouter.use(securityHeaders) before requireAuth so the three headers are present on every response, including 401 unauthenticated responses

src/routes/devicesRevoke.ts

  • Same — securityHeaders mounted before requireAuth on devicesRevokeRouter

src/index.ts

  • Imported devicesRevokeRouter and mounted it at /api/me/devices/:id/revoke (it was defined but not yet wired up in the main app)

tests/devicesSecurityHeaders.test.ts (new)

13 focused tests covering:

  • Content-Security-Policy, X-Content-Type-Options, Referrer-Policy individually on a 200 GET /api/me/devices response
  • All three headers together asserted against API_SECURITY_HEADERS (single source of truth)
  • CSP value verified as deny-all: default-src 'none'; frame-ancestors 'none'; base-uri 'none'
  • Headers present on 401 unauthenticated responses (middleware fires before auth)
  • All three headers on POST /api/me/devices/:id/revoke — 200, 400 (invalid UUID), 404 (device not found)

Headers Applied

Header Value
Content-Security-Policy default-src 'none'; frame-ancestors 'none'; base-uri 'none'
X-Content-Type-Options nosniff
Referrer-Policy no-referrer

Test Results

PASS tests/devicesSecurityHeaders.test.ts
  GET /api/me/devices — security headers
    ✓ sets Content-Security-Policy on a 200 response
    ✓ sets X-Content-Type-Options: nosniff on a 200 response
    ✓ sets Referrer-Policy: no-referrer on a 200 response
    ✓ sets all three headers on a 200 response with devices present
    ✓ header values match API_SECURITY_HEADERS constant (single source of truth)
    ✓ CSP policy is deny-all
  GET /api/me/devices — security headers present on 401 (unauthenticated)
    ✓ returns security headers even when requireAuth rejects the request
  POST /api/me/devices/:id/revoke — security headers
    ✓ sets Content-Security-Policy on a revoke 200 response
    ✓ sets X-Content-Type-Options on a revoke 200 response
    ✓ sets Referrer-Policy on a revoke 200 response
    ✓ sets all three security headers on a 200 revoke response
    ✓ sets all three security headers on a 404 response (device not found)
    ✓ sets all three security headers on a 400 response (invalid UUID)

Tests: 13 passed, 13 total

Closes #594

…icy) to /api/me/devices

Mount securityHeaders middleware on devicesRouter and devicesRevokeRouter
before requireAuth, ensuring all three headers are set on every response —
including 401/403 unauthenticated responses.

Also imports and mounts devicesRevokeRouter at /api/me/devices/:id/revoke
in src/index.ts so the route is reachable in the running app.

Adds 13 focused tests in tests/devicesSecurityHeaders.test.ts covering:
- Content-Security-Policy, X-Content-Type-Options, Referrer-Policy on 200 GET
- header values asserted against API_SECURITY_HEADERS (single source of truth)
- headers present on 401 unauthenticated responses
- all three headers on POST /devices/:id/revoke (200, 400, 404)

Closes Predictify-org#594
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@thelmaoffiong Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit 8496057 into Predictify-org:main Jul 29, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Merged into main via admin resolver (-X theirs).

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

LGTM ✅ green CI, clean work — merging!

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.

Add security header sweep for /api/devices [b#020]

2 participants