Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cross-origin-resource-policy response header #2394

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

**Features**:

- Add `Cross-Origin-Resource-Policy` HTTP header to responses. ([#2394](https://github.com/getsentry/relay/pull/2394))


## 23.7.2

**Features**:
Expand Down
6 changes: 5 additions & 1 deletion relay-server/src/actors/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;

use axum::http::{header, HeaderValue};
use axum::http::{header, HeaderName, HeaderValue};
use axum::ServiceExt;
use axum_server::{AddrIncomingConfig, Handle, HttpConfig};
use relay_config::Config;
Expand Down Expand Up @@ -75,6 +75,10 @@ impl Service for HttpServer {
header::SERVER,
HeaderValue::from_static(constants::SERVER),
))
.layer(SetResponseHeaderLayer::overriding(
HeaderName::from_static("cross-origin-resource-policy"),
HeaderValue::from_static("cross-origin"),
))
.layer(NewSentryLayer::new_from_top())
.layer(SentryHttpLayer::with_transaction())
.layer(middlewares::trace_http_layer())
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,23 @@ def test_compression(mini_sentry, relay, content_encoding):
data=encodings[content_encoding](b'{"message": "hello world"}'),
)
response.raise_for_status()


@pytest.mark.parametrize(
"cross_origin_resource_policy",
[
"cross-origin",
],
)
def test_corp_response_header(mini_sentry, relay, cross_origin_resource_policy):
project_id = 42
mini_sentry.add_basic_project_config(project_id)
relay = relay(mini_sentry)

response = relay.post(
f"/api/42/store/?sentry_key={mini_sentry.get_dsn_public_key(project_id)}",
)

assert (
response.headers["cross-origin-resource-policy"] == cross_origin_resource_policy
)