Skip to content

Conversation

@maximthomas
Copy link
Contributor

No description provided.

@maximthomas maximthomas requested a review from vharseko July 9, 2025 06:37
@maximthomas
Copy link
Contributor Author

Fixes #877

@vharseko vharseko requested a review from aldaris July 9, 2025 07:21
Copy link
Contributor

@aldaris aldaris left a comment

Choose a reason for hiding this comment

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

I've always found it strange why the CORSService was trying to implement the whole validation. Realistically the only thing the cors service should do is to check whether the current origin is amongst the accepted Origins and set the header for that origin only. Another optimisation would be to check if there is only one accepted origin, and then just set all the headers and let the browser print all the errors it wants to the JS console. (according to the spec looking at JS console is a legitimate way to debug CORS related problems anyways.)

Of course the best would be if it would be possible to set headers/credentials/etc settings on a per origin basis, and not expose/allow unnecessary headers/etc for ALL the origins, like the current version of the filter does. Maybe a feature request for down the line?

res.setContentType("application/json");
res.setCharacterEncoding("UTF-8");
res.getWriter().write(jsonValue.toString());
res.setStatus(resourceException.getCode());
Copy link
Contributor

Choose a reason for hiding this comment

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

You should set the response status before writing anything to the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed in c51d44f

JsonValue jsonValue = resourceException.toJsonValue();
res.setContentType("application/json");
res.setCharacterEncoding("UTF-8");
res.getWriter().write(jsonValue.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Just keep in mind that JsonValue#toString doesn't always return actual proper JSON. If you call it on something like a Map value (result of json.get(field)), it will just print out the "value", not a valid JSON.

@vharseko vharseko merged commit 2ecfbf4 into OpenIdentityPlatform:master Jul 11, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants