Skip to content

Add CORS preflight (OPTIONS) test coverage for mutating routes in app.ts #151

Description

@Jagadeeshftw

📌 Description

app.ts mounts the cors middleware with config.corsOrigins (or unrestricted, if unset), but there's no apparent test exercising an actual OPTIONS preflight request against a mutating route (e.g. POST /api/v1/anchors) to confirm the configured corsOrigins allowlist is actually honored by the cors package's preflight response headers.

🧩 Requirements and context

  • Add a test booting createApp() with CORS_ORIGIN set to a specific origin, issuing an OPTIONS preflight to a mutating route with a matching Origin header, and asserting Access-Control-Allow-Origin reflects it.
  • Add a test with a non-matching Origin header asserting the header is absent/doesn't reflect the disallowed origin.
  • Add a test with CORS_ORIGIN unset asserting the current unrestricted-origin behavior (documented in config.ts) still holds.

🛠️ Suggested execution

  • Add tests to src/config.test.ts-adjacent app-level tests or a new cors.test.ts, constructing createApp() under each CORS_ORIGIN configuration and issuing supertest OPTIONS requests.

✅ Acceptance criteria

  • New tests confirm allowed origins are reflected, disallowed origins are not, and the unrestricted default behaves as documented.

🔒 Security notes

Verifies the CORS allowlist configuration actually takes effect at the HTTP layer, not just in config.ts's parsing logic — a misconfigured or silently-ignored CORS setting is a real cross-origin exposure risk.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuesecuritySecurity hardeningtestingTests and coverage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions