Skip to content

SPR-15708 - Add debug logging for CORS rejections #1466

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

Closed
wants to merge 1 commit into from
Closed
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 @@ -126,7 +126,23 @@ protected boolean handleInternal(ServerHttpRequest request, ServerHttpResponse r
List<String> requestHeaders = getHeadersToUse(request, preFlightRequest);
List<String> allowHeaders = checkHeaders(config, requestHeaders);

if (allowOrigin == null || allowMethods == null || (preFlightRequest && allowHeaders == null)) {
if (allowOrigin == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To be moved just bellow checkOrigin invocation ?

logger.debug("rejecting request because CORS processor cannot determine " +
Copy link
Contributor

Choose a reason for hiding this comment

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

What about a message like "Rejecting CORS request because '" + requestOrigin + "' origin is not allowed"

"request origin");
rejectRequest(response);
return false;
}

if (allowMethods == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To be moved just bellow checkMethods invocation ?

logger.debug("rejecting request because CORS processor cannot determine " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar remark than for origin for the message

"the allowed methods for the response of a pre-flight request");
rejectRequest(response);
return false;
}

if ((preFlightRequest && allowHeaders == null)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To be moved just bellow checkHeaders invocation ?

logger.debug("rejecting request because CORS processor cannot determine " +
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar remark than for origin for the message

Copy link
Author

Choose a reason for hiding this comment

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

I'm not going to get to this any time soon - feel free to reject or do own fix.

"the allowed headers for the response of a pre-flight request");
rejectRequest(response);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,23 @@ protected boolean handleInternal(ServerWebExchange exchange,
List<String> requestHeaders = getHeadersToUse(request, preFlightRequest);
List<String> allowHeaders = checkHeaders(config, requestHeaders);

if (allowOrigin == null || allowMethods == null || (preFlightRequest && allowHeaders == null)) {
if (allowOrigin == null) {
logger.debug("rejecting request because CORS processor cannot determine " +
"request origin");
rejectRequest(response);
return false;
}

if (allowMethods == null) {
logger.debug("rejecting request because CORS processor cannot determine " +
"the allowed methods for the response of a pre-flight request");
rejectRequest(response);
return false;
}

if ((preFlightRequest && allowHeaders == null)) {
logger.debug("rejecting request because CORS processor cannot determine " +
"the allowed headers for the response of a pre-flight request");
rejectRequest(response);
return false;
}
Expand Down