Skip to content

Conversation

@Im-Madhur-Gupta
Copy link
Collaborator

@Im-Madhur-Gupta Im-Madhur-Gupta commented Jan 27, 2026

This PR is to be merged ONLY if the security team detects abuse of the backend as it currently does not have CORS protection live, this was done after an agreement that allowing users to connect to backend directly and receive raw event payloads would be a good practice as this is an example app.

@vercel
Copy link

vercel bot commented Jan 27, 2026

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

Project Deployment Review Updated (UTC)
monode Ready Ready Preview, Comment Jan 27, 2026 5:19pm

Request Review

@Im-Madhur-Gupta Im-Madhur-Gupta changed the title feat: implement origin validation for WebSocket connections chore(backend): implement origin validation for WebSocket connections Jan 27, 2026
Comment on lines +334 to +355
match origin {
Some(o) if o == ALLOWED_ORIGIN => {
info!("Accepted connection from allowed origin: {}", o);
Ok(response)
}
Some(o) => {
warn!("Rejected connection from disallowed origin: {}", o);
let error_response = WsResponse::builder()
.status(hyper::StatusCode::FORBIDDEN)
.body(None)
.unwrap();
Err(error_response)
}
None => {
warn!("Rejected connection with no Origin header from {}", addr);
let error_response = WsResponse::builder()
.status(hyper::StatusCode::FORBIDDEN)
.body(None)
.unwrap();
Err(error_response)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
match origin {
Some(o) if o == ALLOWED_ORIGIN => {
info!("Accepted connection from allowed origin: {}", o);
Ok(response)
}
Some(o) => {
warn!("Rejected connection from disallowed origin: {}", o);
let error_response = WsResponse::builder()
.status(hyper::StatusCode::FORBIDDEN)
.body(None)
.unwrap();
Err(error_response)
}
None => {
warn!("Rejected connection with no Origin header from {}", addr);
let error_response = WsResponse::builder()
.status(hyper::StatusCode::FORBIDDEN)
.body(None)
.unwrap();
Err(error_response)
}
}
match origin {
Some(o) => {
if o == ALLOWED_ORIGIN {
info!("Accepted connection from allowed origin: {}", o);
Ok(response)
} else {
warn!("Rejected connection from disallowed origin: {}", o);
let error_response = WsResponse::builder()
.status(hyper::StatusCode::FORBIDDEN)
.body(None)
.unwrap();
Err(error_response)
}
}
None => {
warn!("Rejected connection with no Origin header from {}", addr);
let error_response = WsResponse::builder()
.status(hyper::StatusCode::FORBIDDEN)
.body(None)
.unwrap();
Err(error_response)
}
}

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.

3 participants