Skip to content

feat(auth): require JWT for GET /api/* endpoints with optional public demo mode#144

Open
TFT444 wants to merge 8 commits into
devfrom
feat/auth-demo-mode
Open

feat(auth): require JWT for GET /api/* endpoints with optional public demo mode#144
TFT444 wants to merge 8 commits into
devfrom
feat/auth-demo-mode

Conversation

@TFT444

@TFT444 TFT444 commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes a security gap where all GET requests to /api/* were publicly accessible without a JWT. Real Azure scan data including findings, compliance status, score, and resources should not be readable without authentication in production.

Type of change

  • Bug fix
  • API endpoint
  • Documentation

Changes

api/app.py — removed _is_public_get() which was making all /api/* GET routes public. Replaced with _ALWAYS_PUBLIC set containing only / and /health. Added OPENSHIELD_PUBLIC_DEMO=true env var support so deployments running a public demo dashboard can still allow unauthenticated GET requests explicitly. Added DATABASE_URL guard so the app can start without a database during tests and local dev.

tests/test_auth.py — new test file covering default mode (GET /api/* returns 401 without JWT) and demo mode (GET /api/* allowed without JWT, POST always requires JWT, /health always public).

.github/workflows/ci.yml — added tests/test_auth.py to the CI pytest command so auth coverage is enforced on every PR.

docs/api-reference.md — updated auth section to reflect the new default behavior and added a reference table explaining demo mode vs production mode.

Acceptance criteria

  • /health remains public in all environments
  • Production /api/* GET routes return 401 without a valid JWT by default
  • Public demo mode can explicitly allow unauthenticated GET routes via OPENSHIELD_PUBLIC_DEMO=true
  • Docs explain when JWT is required and when demo mode applies
  • Tests cover default production behavior and explicit public demo behavior

Testing

  • Verified locally — app starts without DATABASE_URL
  • No hardcoded credentials or secrets
  • All CI checks passing

Checklist

  • My code follows the patterns in CONTRIBUTING.md
  • I have not committed any real Azure credentials or secrets
  • My branch name follows the convention: feat/description

Related issue

Closes #141

TFT444 added 4 commits June 15, 2026 12:15
Refactor public access logic and improve database migration handling.
This file contains tests for JWT authentication middleware, including both production and demo modes. It tests various endpoints for JWT requirements and public access.
Added authentication details and public demo mode information to the API reference.
@TFT444 TFT444 requested a review from Vishnu2707 June 15, 2026 11:37
@TFT444 TFT444 self-assigned this Jun 15, 2026
Removed DATABASE_URL environment variable from rule regression tests.
H-Sihan
H-Sihan previously approved these changes Jun 18, 2026
@Vishnu2707

Copy link
Copy Markdown
Member

@TFT444 , kindly fix the conflicts!

Revisit the PR

@TFT444

TFT444 commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

@Vishnu2707 Conflict has been resolved!

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.

[SECURITY] Require auth for production API GET endpoints unless demo mode is explicit

3 participants