Skip to content

CORS is wide open on the server with no origin restrictions#12

Open
Ghvstcode wants to merge 1 commit intomainfrom
sustn/cors-is-wide-open-on-the-server-with-no-origin-restrictions
Open

CORS is wide open on the server with no origin restrictions#12
Ghvstcode wants to merge 1 commit intomainfrom
sustn/cors-is-wide-open-on-the-server-with-no-origin-restrictions

Conversation

@Ghvstcode
Copy link
Copy Markdown
Owner

SUSTN Auto-PR

The server in server/src/index.ts:8 applies cors() middleware with no configuration, which means Access-Control-Allow-Origin: * is set on all routes. This allows any website to make authenticated requests to the SUSTN server endpoints — including the metrics ingestion endpoint which accepts a Bearer token.

While the desktop app communicates directly with the server (not through a browser), the auth callback page IS served in a browser during the OAuth flow. An attacker could create a malicious webpage that, if a SUSTN user visits it, could submit crafted metric events to the server using a stolen or guessed token, or probe the auth endpoints.

The fix should restrict CORS origins to only the domains that legitimately need access. For the auth callback HTML page, the server URL itself should be allowed. For the metrics endpoint called from the Tauri app, CORS isn't needed at all since it's not a browser request. Consider either removing CORS entirely (since the primary client is a desktop app, not a browser) or restricting it to the server's own origin for the auth callback flow.

Branch: sustn/cors-is-wide-open-on-the-server-with-no-origin-restrictions

Remove the unconfigured `cors()` middleware that was setting
`Access-Control-Allow-Origin: *` on all routes, allowing any website
to make cross-origin requests to the server.

CORS is unnecessary for this server because:
- The primary client is the Tauri desktop app, which doesn't use
  browser fetch and is unaffected by CORS
- The auth callback HTML page is served directly by the server
  itself (same-origin), so no cross-origin access is needed
- The /health and /metrics endpoints have no legitimate browser
  cross-origin consumers

Removing CORS entirely is the most secure option. If cross-origin
browser access is needed in the future, CORS can be re-added with
an explicit origin allowlist.

SUSTN-Task: 950c7bb2-9bba-4e03-9319-4a5b88c71b54
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sustn Ready Ready Preview, Comment Mar 28, 2026 6:54pm

const app = new Hono<{ Bindings: Bindings }>();

app.use("*", logger());
app.use("*", cors());
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes no sense? we are just removing CORS instead of whityelisting the URLS?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

@@ -1,5 +1,4 @@
import { Hono } from "hono";
import { cors } from "hono/cors";
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback!

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.

1 participant