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: disallow multiple auth headers #3607

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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public boolean isAuthenticated(Map<String, List<String>> headers) {
}

private boolean checkApiKeyValid(List<String> apiKeys) {
return apiKeys.stream().anyMatch(hardCodedApiKey::equalsIgnoreCase);
return apiKeys.size() == 1 && apiKeys.stream().allMatch(hardCodedApiKey::equalsIgnoreCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void isAuthorized_notAuthorized() {
}

@Test
void isAuthorized_multipleValues_oneAuthorized() {
void isAuthorized_multipleValues_oneAuthorized_shouldReturnFalse() {
var map = Map.of("x-api-key", List.of("invalid_api_key", TEST_API_KEY));
assertThat(service.isAuthenticated(map)).isTrue();
assertThat(service.isAuthenticated(map)).isFalse();
}
}
Loading