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

fix: CORS header typo Access-Control-Allow-Origin #8024

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion lib/ProductOpener/HTTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ sub get_cors_headers ($allow_credentials = 0, $sub_domain_only = 0) {
}
}
}
$headers_ref->{"Access-Control-Allow-Origins"} = $allow_origins;
$headers_ref->{"Access-Control-Allow-Origin"} = $allow_origins;
if ($allow_origins ne "*") {
# see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin#cors_and_caching
$headers_ref->{"Vary"} = "Origin";
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/cors.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ my $tests_ref = [
path => '/cgi/auth.pl',
expected_status_code => 403, # we are not authenticated
headers => {
"Access-Control-Allow-Origins" => "http://world.openfoodfacts.localhost",
"Access-Control-Allow-Origin" => "http://world.openfoodfacts.localhost",
"Access-Control-Allow-Credentials" => "true",
"Vary" => "Origin"
},
Expand All @@ -42,7 +42,7 @@ my $tests_ref = [
path => '/cgi/auth.pl',
expected_status_code => 403, # we are not authenticated
headers => {
"Access-Control-Allow-Origins" => "http://world.openfoodfacts.localhost",
"Access-Control-Allow-Origin" => "http://world.openfoodfacts.localhost",
"Access-Control-Allow-Credentials" => "true",
"Vary" => "Origin"
},
Expand All @@ -55,7 +55,7 @@ my $tests_ref = [
expected_status_code => 403, # because Options triggers a GET, and we are unauthenticated
headers_in => {"Origin" => "http://other.localhost"},
headers => {
"Access-Control-Allow-Origins" => "*",
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Credentials" => undef,
},
expected_type => "html",
Expand All @@ -66,7 +66,7 @@ my $tests_ref = [
path => '/api/v3/product/0000002',
expected_status_code => 404,
headers => {
"Access-Control-Allow-Origins" => "*",
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "HEAD, GET, PATCH, POST, PUT, OPTIONS",
},
expected_type => "html",
Expand All @@ -77,7 +77,7 @@ my $tests_ref = [
path => '/api/v3/product/0000002',
expected_status_code => 404,
headers => {
"Access-Control-Allow-Origins" => "*",
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "HEAD, GET, PATCH, POST, PUT, OPTIONS",
},
expected_type => "html",
Expand All @@ -88,7 +88,7 @@ my $tests_ref = [
path => '/api/v2/product/0000002',
expected_status_code => 404,
headers => {
"Access-Control-Allow-Origins" => "*",
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "HEAD, GET, PATCH, POST, PUT, OPTIONS",
},
expected_type => "html",
Expand All @@ -99,7 +99,7 @@ my $tests_ref = [
path => '/api/v2/product/0000002',
expected_status_code => 404,
headers => {
"Access-Control-Allow-Origins" => "*",
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "HEAD, GET, PATCH, POST, PUT, OPTIONS",
},
expected_type => "html",
Expand All @@ -120,7 +120,7 @@ $tests_ref = [
path => '/cgi/auth.pl',
expected_status_code => 200, # authenticated
headers => {
"Access-Control-Allow-Origins" => "http://world.openfoodfacts.localhost",
"Access-Control-Allow-Origin" => "http://world.openfoodfacts.localhost",
"Access-Control-Allow-Credentials" => "true",
"Vary" => "Origin"
},
Expand All @@ -133,7 +133,7 @@ $tests_ref = [
expected_status_code => 200, # authenticated
headers_in => {"Origin" => "http://other.localhost"},
headers => {
"Access-Control-Allow-Origins" => "*",
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Credentials" => undef,
},
expected_type => "html",
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/http.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sub fake_headers_in ($fake_arg) {
};

my $headers_ref = get_cors_headers();
my $expected_ref = {%$expected_base_ref, ("Access-Control-Allow-Origins" => "*")};
my $expected_ref = {%$expected_base_ref, ("Access-Control-Allow-Origin" => "*")};
is_deeply($headers_ref, $expected_ref);

# allow credentials from sub domains
Expand All @@ -48,7 +48,7 @@ sub fake_headers_in ($fake_arg) {
$expected_ref = {
%$expected_base_ref,
(
"Access-Control-Allow-Origins" => "https://fr.openfoodfacts.localhost",
"Access-Control-Allow-Origin" => "https://fr.openfoodfacts.localhost",
"Access-Control-Allow-Credentials" => "true",
"Vary" => "Origin"
)
Expand All @@ -58,22 +58,22 @@ sub fake_headers_in ($fake_arg) {
# but do not allow for alien domains, we do not block request, but do not allow credentials
$HEADERS_IN = {"Origin" => "https://fr.example.com"};
$headers_ref = get_cors_headers(1);
$expected_ref = {%$expected_base_ref, ("Access-Control-Allow-Origins" => "*")};
$expected_ref = {%$expected_base_ref, ("Access-Control-Allow-Origin" => "*")};
is_deeply($headers_ref, $expected_ref);

# restrict to subdomain -> allow sub domain
$HEADERS_IN = {"Origin" => "https://fr.openfoodfacts.localhost"};
$headers_ref = get_cors_headers(0, 1);
$expected_ref = {
%$expected_base_ref,
("Access-Control-Allow-Origins" => "https://fr.openfoodfacts.localhost", "Vary" => "Origin")
("Access-Control-Allow-Origin" => "https://fr.openfoodfacts.localhost", "Vary" => "Origin")
};
is_deeply($headers_ref, $expected_ref);
$headers_ref = get_cors_headers(1, 1);
$expected_ref = {
%$expected_base_ref,
(
"Access-Control-Allow-Origins" => "https://fr.openfoodfacts.localhost",
"Access-Control-Allow-Origin" => "https://fr.openfoodfacts.localhost",
"Access-Control-Allow-Credentials" => "true",
"Vary" => "Origin"
)
Expand All @@ -84,7 +84,7 @@ sub fake_headers_in ($fake_arg) {
$HEADERS_IN = {"Origin" => "https://fr.example.com"};
$headers_ref = get_cors_headers(0, 1);
$expected_ref = {%$expected_base_ref,
("Access-Control-Allow-Origins" => "https://openfoodfacts.localhost", "Vary" => "Origin")};
("Access-Control-Allow-Origin" => "https://openfoodfacts.localhost", "Vary" => "Origin")};
is_deeply($headers_ref, $expected_ref);
$headers_ref = get_cors_headers(1, 1);
is_deeply($headers_ref, $expected_ref);
Expand Down