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

[OB3] Prevent overriding MTLS Cert Header at TokenFilter #99

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
* Copyright (c) 2023-2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -132,15 +132,15 @@ private ServletRequest appendTransportHeader(ServletRequest request, ServletResp
if (request instanceof HttpServletRequest) {
Object certAttribute = request.getAttribute(IdentityCommonConstants.JAVAX_SERVLET_REQUEST_CERTIFICATE);
String x509Certificate = ((HttpServletRequest) request).getHeader(IdentityCommonUtil.getMTLSAuthHeader());
if (certAttribute != null) {
if (new IdentityCommonHelper().isTransportCertAsHeaderEnabled() && x509Certificate != null) {
return request;
} else if (certAttribute != null) {
RequestWrapper requestWrapper = new RequestWrapper((HttpServletRequest) request);
X509Certificate certificate = IdentityCommonUtil.getCertificateFromAttribute(certAttribute);
requestWrapper.setHeader(IdentityCommonUtil.getMTLSAuthHeader(),
new IdentityCommonHelper().encodeCertificateContent(certificate));
return requestWrapper;
} else if (new IdentityCommonHelper().isTransportCertAsHeaderEnabled() && x509Certificate != null) {
return request;
} else {
} else {
getDefaultTokenFilter().handleValidationFailure((HttpServletResponse) response,
HttpServletResponse.SC_BAD_REQUEST, IdentityCommonConstants.OAUTH2_INVALID_REQUEST_MESSAGE,
"Transport certificate not found in the request");
Expand Down
Loading