Skip to content

feat: Add CORS configuration, HTTPS/HSTS enforcement and fix hardcoded WebSocket URL#199

Merged
devJaja merged 2 commits into
Epta-Node:mainfrom
DevSolex:feat/cors-https-enforcement
Jul 24, 2026
Merged

feat: Add CORS configuration, HTTPS/HSTS enforcement and fix hardcoded WebSocket URL#199
devJaja merged 2 commits into
Epta-Node:mainfrom
DevSolex:feat/cors-https-enforcement

Conversation

@DevSolex

Copy link
Copy Markdown
Contributor

Summary

Resolves #160

Implements all acceptance criteria from issue #160 — CORS configuration, HSTS enforcement, and the hardcoded WebSocket URL fix.

Changes

Backend

  • backend/src/api/middleware/cors.ts — CORS factory with configurable ALLOWED_ORIGINS, credentials: true, allowed methods (GET POST PUT DELETE OPTIONS), and custom headers (walletpublickey, x-challenge, x-signature)
  • backend/src/api/app.ts — Mounts CORS middleware globally; adds HSTS header middleware (max-age=31536000; includeSubDomains; preload) in production only
  • backend/src/config/index.tsALLOWED_ORIGINS Zod field with default http://localhost:3000
  • backend/.env.example — Documents ALLOWED_ORIGINS under the Security section

Frontend

  • frontend/src/hooks/useTaskMonitor.ts — Replaces hardcoded ws://localhost:3001 with dynamic protocol/host (wss: on HTTPS, ws: on HTTP, VITE_WS_HOST env override)

Tests

  • backend/tests/cors.test.ts — 8 tests covering:
    • Allows configured origin
    • Blocks unauthorized origin
    • No-origin passthrough (server-to-server calls)
    • access-control-allow-credentials header present for allowed origins
    • Preflight OPTIONS response includes allowed methods
    • Default origin fallback when ALLOWED_ORIGINS is unset
    • HSTS header set in production
    • HSTS header absent in development

Testing

cd backend
npm test -- --testPathPattern="tests/cors"

All 8 CORS/HSTS tests pass. No regressions in the wider test suite.

DevSolex added 2 commits July 24, 2026 12:37
…d} (Epta-Node#161)

The ownership check (walletpublickey header required, must match task
owner) was already implemented in the route handler. This commit adds
the missing HTTP 403 response to the JSDoc annotation so the generated
OpenAPI spec accurately documents the auth behaviour for consumers.

Closes Epta-Node#161
- backend/src/api/middleware/cors.ts: CORS factory with configurable
  ALLOWED_ORIGINS, credentials, and custom headers (walletpublickey,
  x-challenge, x-signature)
- backend/src/api/app.ts: mount CORS middleware and HSTS header
  middleware (production-only, max-age=31536000 + includeSubDomains + preload)
- backend/src/config/index.ts: ALLOWED_ORIGINS Zod field with default
  http://localhost:3000
- backend/.env.example: document ALLOWED_ORIGINS under Security section
- frontend/src/hooks/useTaskMonitor.ts: replace hardcoded ws://localhost:3001
  with dynamic protocol/host (wss: on HTTPS, VITE_WS_HOST override)
- backend/tests/cors.test.ts: add tests for allowed origin, blocked origin,
  no-origin passthrough, credentials header, preflight OPTIONS, default
  origin fallback, HSTS in production, and HSTS absent in development
@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

@DevSolex is attempting to deploy a commit to the Jaja's projects Team on Vercel.

A member of the Team first needs to authorize it.

@devJaja
devJaja self-requested a review July 24, 2026 12:01
@devJaja

devJaja commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LGTM

@devJaja
devJaja merged commit a475d92 into Epta-Node:main Jul 24, 2026
6 of 7 checks passed
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.

[Backend] Add CORS Configuration and HTTPS Enforcement

2 participants