Skip to content

Default CORS_ORIGINS omits the frontend dev server port 8080 — browser calls to the API are blocked #43

Closed

Description

@amar-python

Summary

api/config.py defaulted CORS_ORIGINS to http://localhost:5173,http://localhost:3000. The React frontend's Vite dev server (npm run dev / scripts/start-frontend.ps1, via @lovable.dev/vite-tanstack-config) listens on port 8080. So with default settings the browser's CORS preflight from http://localhost:8080 gets no Access-Control-Allow-Origin header, and every API call from the UI is blocked.

Impact

  • A fresh local setup that follows the README (API on :8000, frontend on :8080) fails in the browser unless the developer knows to export CORS_ORIGINS by hand. docs/QUICKSTART.md documented that workaround; env.dev.example and docs/ENV_VARIABLES.md did not.
  • scripts/start-frontend.ps1 also said the frontend runs on http://localhost:5173, which is wrong and adds to the confusion.

Steps to reproduce

  1. Start the API with no CORS_ORIGINS set.
  2. Send a preflight: OPTIONS /api/csv/files with Origin: http://localhost:8080 and Access-Control-Request-Method: GET.
  3. Expected: 200 with access-control-allow-origin: http://localhost:8080.
  4. Actual: 400 Disallowed CORS origin, with no allow-origin header.

Notes

Activity

  1. added a commit that references this issue on Oct 10, 2026
  2. amar-python commented on Oct 10, 2026

    @amar-python
    OwnerAuthor

    Fixed and verified

    Fix: 15268ae. The default CORS_ORIGINS in api/config.py is now http://localhost:8080,http://localhost:5173,http://localhost:3000, so the Vite dev server's port is allowed and the old ports still work. env.dev.example, docs/ENV_VARIABLES.md, README.md and scripts/start-frontend.ps1 (which said 5173) are updated to match. Deployments that set CORS_ORIGINS explicitly are unaffected.

    Regression tests

    Test What it proves
    tests/unit/test_db_pool.py::test_cors_allows_frontend_dev_server_by_default A preflight OPTIONS /api/csv/files from Origin: http://localhost:8080 returns 200 with access-control-allow-origin: http://localhost:8080
    tests/unit/test_db_pool.py::test_cors_still_refuses_unlisted_origins (added in 09ff668) The fix did not loosen the policy: a preflight from http://evil.example is still 400 with no allow-origin header
    tests/unit/test_config_auth.py::TestSettings::test_defaults With CORS_ORIGINS unset, the default list is exactly [":8080", ":5173", ":3000"] on localhost

    The tests catch the bug. Run against the pre-fix source (15268ae~1):

    • A preflight from :8080 returned 400 'Disallowed CORS origin' with no access-control-allow-origin, which is the behaviour described above.
    • FAILED test_cors_allows_frontend_dev_server_by_default and FAILED test_defaults. test_cors_still_refuses_unlisted_origins passed both before and after, as it should.

    They pass with the fix:

    • Local: 3/3, and the full non-accessibility suite passes (378 tests).
    • CI on 6f6814a (PR Group tests into unit, system, SIT, performance, accessibility and UAT #41, all 4 checks green):
      • integration (postgres service) job: executed 392 · PASSED 392 · FAILED 0 · SKIPPED 0, RESULT: PASS. Only the 23 accessibility tests were not run in that job, so all three tests above passed there.
      • free-tier (Linux) and python-validator-tests (Windows) also ran the unit tests green.

    Note: the fix is on branch claude/elegant-bohr-zn28zn and reaches main when PR #41 is merged.

    Closing as fixed.


    Generated by Claude Code

  3. added a commit that references this issue on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions