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

limit-allow-origin-bug #503

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public abstract class ApiGatewayHandler<I, O> extends RestRequestHandler<I, O> {
public static final String ALL_ORIGINS_ALLOWED = "*";
public static final String ORIGIN_DELIMITER = ",";
public static final String FALLBACK_ORIGIN = "https://nva.sikt.no";
public static final String ORIGIN_HEADER = "origin";

private final ObjectMapper objectMapper;

Expand Down Expand Up @@ -83,7 +84,7 @@ private String readAllowedOrigin(RequestInfo requestInfo) {
if (originsList.contains(ALL_ORIGINS_ALLOWED)) {
return ALL_ORIGINS_ALLOWED;
}
var requestOrigin = requestInfo.getHeader("Origin");
Copy link
Contributor

Choose a reason for hiding this comment

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

HTTP header names should be case insensitive, so this is a weakness in our implementation in RequestInfo I would say.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed the actual issue.

var requestOrigin = requestInfo.getHeader(ORIGIN_HEADER);
if (originsList.contains(requestOrigin)) {
return requestOrigin;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nva.commons.apigateway;

import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static com.google.common.net.HttpHeaders.ORIGIN;
import static com.google.common.net.HttpHeaders.STRICT_TRANSPORT_SECURITY;
import static com.google.common.net.HttpHeaders.VARY;
import static com.google.common.net.HttpHeaders.X_CONTENT_TYPE_OPTIONS;
Expand All @@ -14,6 +13,7 @@
import static nva.commons.apigateway.ApiGatewayHandler.ALLOWED_ORIGIN_ENV;
import static nva.commons.apigateway.ApiGatewayHandler.ALL_ORIGINS_ALLOWED;
import static nva.commons.apigateway.ApiGatewayHandler.FALLBACK_ORIGIN;
import static nva.commons.apigateway.ApiGatewayHandler.ORIGIN_HEADER;
import static nva.commons.apigateway.ApiGatewayHandler.REQUEST_ID;
import static nva.commons.apigateway.MediaTypes.APPLICATION_PROBLEM_JSON;
import static nva.commons.apigateway.RestConfig.defaultRestObjectMapper;
Expand Down Expand Up @@ -686,7 +686,7 @@ private JsonNode createHeaders() {
Map<String, String> headers = new ConcurrentHashMap<>();
headers.put(HttpHeaders.ACCEPT, MediaType.JSON_UTF_8.toString());
headers.put(CONTENT_TYPE, MediaType.JSON_UTF_8.toString());
headers.put(ORIGIN, "https://example.com");
headers.put(ORIGIN_HEADER, "https://example.com");
headers.put(X_CONTENT_TYPE_OPTIONS, "nosniff");
headers.put(STRICT_TRANSPORT_SECURITY, "max-age=63072000; includeSubDomains; preload");
return createHeaders(headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'com.github.bibsysdev'
version = '1.40.4'
version = '1.40.5'


java.sourceCompatibility = JavaVersion.VERSION_17 // source-code version and must be <= targetCompatibility
Expand Down
Loading