Skip to content

BUG: Restrict CORS middleware to only allow localhost origins instead of wildcard (*) #640

@srijan2607

Description

@srijan2607

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Current configuration allows ANY origin to make requests to the local API, which:

  • Creates potential security vulnerability
  • Could allow malicious websites to access user's local photo data
  • Violates privacy-first principle

Changes

  • Updated CORS allow_origins to whitelist only known localhost origins
  • Specified exact HTTP methods and headers instead of wildcards
  • Added Tauri-specific origins for production builds

Before:

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # Allows all origins
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

After:

app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        "http://localhost:1420",  # Tauri dev server
        "http://localhost:5173",  # Vite dev server
        "tauri://localhost",      # Tauri production
        "https://tauri.localhost", # Tauri HTTPS
    ],
    allow_credentials=True,
    allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
    allow_headers=["Content-Type", "Accept", "Authorization"],
)

Record

  • I agree to follow this project's Code of Conduct

Checklist before Submitting

  • Have you updated docs for it?
  • Have you added unit tests?
  • Have you made sure unit tests pass?
  • Have you made sure code formatting is correct?
  • Do Your changes passes all tests?

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions