Opened 15 months ago

Last modified 8 months ago

#22062 new defect

Bad requests do not add the Access-Control-Allow-Origin header

Reported by: cypherpunks Owned by: metrics-team
Priority: Medium Milestone:
Component: Metrics/Onionoo Version:
Severity: Normal Keywords: metrics-2018
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

I've found this issue by submitting invalid requests through Atlas. For example, https://atlas.torproject.org/#search/%3Ctest%3E shows in the Firefox Developer Tools Console tab the following message.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://onionoo.torproject.org/summary?search=%3Ctest%3E. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Looking at the Onionoo code, the culprit seems to be the doGet function and more specifically ResourceServlet.java:356 which sets several headers but only when the request has been processed successfully. For invalid requests it calls sendError. According to the Java API sendError

Sends an error response to the client using the specified status code and clears the buffer. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back the error page

I'm not sure which headers sendError clears or updates but I think the setHeader calls can safely be moved to the top of the doGet function to ensure these headers are also included in bad request responses. Unfortunately i have no setup to test this assumption/solution.

Child Tickets

Change History (4)

comment:1 Changed 15 months ago by karsten

Before I try out whether this works and what it might break in unexpected ways: what's the use case for including these headers in responses to bad requests?

comment:2 in reply to:  1 Changed 15 months ago by cypherpunks

Replying to karsten:

Before I try out whether this works and what it might break in unexpected ways: what's the use case for including these headers in responses to bad requests?

I can't speak about the Cache-Control header but including the Access-Control-Allow-Origin header for responses to bad requests would allow browsers to fully load the response and prevent CORS errors from showing up in the console.

comment:3 Changed 10 months ago by karsten

Keywords: metrics-2018 added

comment:4 Changed 8 months ago by irl

This would be required for #8667.

Note: See TracTickets for help on using tickets.