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

Revert "Improve trusted origin validation" #124

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.SecureRandom;
import java.text.MessageFormat;
Expand Down Expand Up @@ -214,8 +212,8 @@ public Either<String, RegistrationRequest> startRegistration(@NonNull String ori
public Either<String, FIDO2RegistrationRequest> startFIDO2Registration(@NonNull String origin)
throws JsonProcessingException, FIDO2AuthenticatorClientException {

validateFIDO2TrustedOrigin(origin);
URL originUrl = getOriginUrl(origin);
validateFIDO2TrustedOrigin(originUrl);
RelyingParty relyingParty = buildRelyingParty(originUrl);

User user = User.getUserFromUserName(getTenantQualifiedUsername());
Expand Down Expand Up @@ -254,8 +252,8 @@ public Either<String, FIDO2RegistrationRequest> startFIDO2UsernamelessRegistrati
String username)
throws JsonProcessingException, FIDO2AuthenticatorClientException {

validateFIDO2TrustedOrigin(origin);
URL originUrl = getOriginUrl(origin);
validateFIDO2TrustedOrigin(originUrl);
RelyingParty relyingParty = buildRelyingParty(originUrl);

if (username == null) {
Expand Down Expand Up @@ -1086,28 +1084,15 @@ private AssertionRequest getAssertionRequest(FIDO2CacheEntry cacheEntry) throws
return request;
}

private void validateFIDO2TrustedOrigin(URL origin) throws FIDO2AuthenticatorClientException {
private void validateFIDO2TrustedOrigin(String origin) throws FIDO2AuthenticatorClientException {

String normalizedOrigin = normalizeOrigin(origin);
readTrustedOrigins();
if (!origins.contains(normalizedOrigin)) {
if (!origins.contains(origin.trim())) {
throw new FIDO2AuthenticatorClientException(INVALID_ORIGIN_MESSAGE,
ERROR_CODE_START_REGISTRATION_INVALID_ORIGIN.getErrorCode());
}
}

private String normalizeOrigin(URL origin) throws FIDO2AuthenticatorClientException {

try {
return new URI(origin.getProtocol(), null, origin.getHost(),
origin.getPort() == -1 ? origin.getDefaultPort() : origin.getPort(),
null, null, null).toString();
} catch (URISyntaxException e) {
throw new FIDO2AuthenticatorClientException(INVALID_ORIGIN_MESSAGE,
ERROR_CODE_START_REGISTRATION_INVALID_ORIGIN.getErrorCode(), e);
}
}

private URL getOriginUrl(String origin) throws FIDO2AuthenticatorClientException {

URL originUrl;
Expand All @@ -1117,6 +1102,7 @@ private URL getOriginUrl(String origin) throws FIDO2AuthenticatorClientException
throw new FIDO2AuthenticatorClientException(INVALID_ORIGIN_MESSAGE,
ERROR_CODE_START_REGISTRATION_INVALID_ORIGIN.getErrorCode(), e);
}

return originUrl;
}

Expand Down