Skip to content

Bug: Fix CORS misconfiguration with wildcard and specific origins #40

@coderabbitai

Description

@coderabbitai

Description

The CORS configuration in backend/app/main.py is incorrectly set up:

allow_origins=["redloop.vercel.app", "*"],

Using both a specific domain AND wildcard "*" defeats the purpose of CORS security.

Problem

  • The wildcard "*" allows all origins, making the specific domain pointless
  • CORS protection is effectively disabled
  • Any website can call your API

Expected Behavior

Should use environment variable with proper origin list:

CORS_ORIGINS = os.getenv("CORS_ORIGINS", "http://localhost:3000").split(",")

app.add_middleware(
    CORSMiddleware,
    allow_origins=CORS_ORIGINS,  # No wildcard!
    allow_credentials=True,
    allow_methods=["GET", "POST", "PUT", "DELETE"],
    allow_headers=["*"],
)

Fix Checklist

  • Remove "*" from allow_origins
  • Use CORS_ORIGINS environment variable
  • Update backend/.env.example:
    CORS_ORIGINS=http://localhost:3000,https://redloop.vercel.app
    
  • Restrict allowed methods (remove wildcards where possible)
  • Test CORS in dev and production

Location

Related

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpriority-highHigh prioritysecuritySecurity related issues

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions