-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fixes #10220 - Implement CrossOriginHandler. #11093
Fixes #10220 - Implement CrossOriginHandler. #11093
Conversation
Introduced CrossOriginHandler. Added cross-origin Jetty module. Added CrossOriginHandler documentation to the programming guide. Added CrossOriginHandler documentation to the operations guide. Added cross-origin headers to the HttpHeader enum. Added test cases. Deprecated ee10 CrossOriginFilter. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@gregw @joakime @lorban @lachlan-roberts things to ponder:
|
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
But if we don't have this
I agree that it doesn't seem necessary to check it on the server because the browser should enforce it. But then I don't understand what the purpose of the
I think we do need something to deal with the CSWSH attacks. |
If you don't have COH, yes, a core Handler would need to deal with the OPTIONS preflight. The preflight just seems an implementation detail of CORS, so not worth delivering it: we short-circuit at COH level.
I think In case of a dynamic decision about
I agree that a configuration to return 400 for mismatched origins is good to have.
We could make a special case for the WebSocket upgrade. However, I wonder whether we need both? So we could have one parameter for generic origin mismatch (defaults to deliver=true), and one specific for WebSocket origin mismatch (defaults to deliver=false). |
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
Works for me.
It says here https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS that:
which seems to imply that the server should do something about it if it cannot accept the request.
I think this is the way to go. |
Sure, but what should the server do? It's a preflight request, so the only things the server can do is to:
Solution 2 is the trivial one so I went for that. Doing an expensive match on the server to figure out you don't want to add the CORS headers (solution 1) or figure out you have to send a 400 (solution 3) seems a lot of unnecessary work. With COH.deliverPreflight=true, an application can do whatever it wants, but needs to be aware of CORS. |
@sbordet why do we not validate the request headers against |
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
Because |
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed some of my previous review comments?
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Ok. I was thinking that the browser might not send a preflight request and we'd have to check the actual headers of the request. But now I see that if it has custom headers the browser should always send a preflight request. |
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
failing test but other than that looks good to me
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/handler/CrossOriginHandler.java
Outdated
Show resolved
Hide resolved
...core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/CrossOriginHandlerTest.java
Show resolved
Hide resolved
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
public boolean handle(Request request, Response response, Callback callback) throws Exception | ||
{ | ||
// The response may change if the Origin header is present, so always add Vary. | ||
response.getHeaders().add(VARY_ORIGIN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ensureField:
response.getHeaders().add(VARY_ORIGIN); | |
response.getHeaders().ensureField(VARY_ORIGIN); |
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Introduced CrossOriginHandler.
Added cross-origin Jetty module.
Added CrossOriginHandler documentation to the programming guide. Added CrossOriginHandler documentation to the operations guide. Added cross-origin headers to the HttpHeader enum. Added test cases.
Deprecated ee10 CrossOriginFilter.