Skip to content

Commit

Permalink
python bridge: drop CORS headers
Browse files Browse the repository at this point in the history
The correct thing for us to do with CORS is not to participate in it at
all, so stop sending the `Access-Control-Allow-Origin` header.

Modify our existing integration test which checks for the presence and
value of the Access-Control-Allow-Origin header and replace it with a
check that all headers are missing.
  • Loading branch information
allisonkarlitskaya committed Jul 17, 2023
1 parent decaf73 commit d95542e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/cockpit/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def serve_file(self, path, channel):
data, (content_type, encoding) = self.files[path]

headers = {
"Access-Control-Allow-Origin": channel.origin,
"Content-Encoding": encoding,
}
if content_type is not None and content_type.startswith('text/html'):
Expand Down
16 changes: 15 additions & 1 deletion test/verify/check-connection
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,21 @@ class TestConnection(testlib.MachineCase):
headers = m.execute("curl -k --head -b cockpit.jar -s https://127.0.0.1:9090/")
self.assertIn(
"default-src 'self' https://127.0.0.1:9090; connect-src 'self' https://127.0.0.1:9090 wss://127.0.0.1:9090", headers)
self.assertIn("Access-Control-Allow-Origin: https://127.0.0.1:9090", headers)
if self.is_pybridge():
# We want to make sure we're *not* sending any CORS headers.
CORS_HEADERS = [
# https://en.wikipedia.org/wiki/Cross-origin_resource_sharing#Response_headers
'Access-Control-Allow-Credentials',
'Access-Control-Expose-Headers',
'Access-Control-Max-Age',
'Access-Control-Allow-Methods',
'Access-Control-Allow-Headers',
]
for cors_header in CORS_HEADERS:
self.assertNotIn(cors_header, headers)
else:
self.assertIn("Access-Control-Allow-Origin: https://127.0.0.1:9090", headers)

# CORP and Frame-Options are also set for dynamic paths
self.assertIn("Cross-Origin-Resource-Policy: same-origin", headers)
self.assertIn("X-Frame-Options: sameorigin", headers)
Expand Down

0 comments on commit d95542e

Please sign in to comment.