-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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>
- Loading branch information
Showing
12 changed files
with
1,419 additions
and
17 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...cumentation/src/main/asciidoc/operations-guide/modules/module-cross-origin.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
[[og-module-cross-origin]] | ||
===== Module `cross-origin` | ||
|
||
The `cross-origin` module provides support for the link:https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS[CORS protocol] implemented by browsers when performing cross-origin requests. | ||
|
||
This module installs the xref:{prog-guide}#pg-server-http-handler-use-cross-origin[`CrossOriginHandler`] in the `Handler` tree; `CrossOriginHandler` inspects cross-origin requests and adds the relevant CORS response headers. | ||
|
||
`CrossOriginHandler` should be used when an application performs cross-origin requests to your server, to protect from link:https://owasp.org/www-community/attacks/csrf[cross-site request forgery] attacks. | ||
|
||
The module properties are: | ||
|
||
---- | ||
include::{jetty-home}/modules/cross-origin.mod[tags=documentation] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
jetty-core/jetty-server/src/main/config/etc/jetty-cross-origin.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
|
||
<Configure id="Server" class="org.eclipse.jetty.server.Server"> | ||
<Call name="insertHandler"> | ||
<Arg> | ||
<New id="CrossOriginHandler" class="org.eclipse.jetty.server.handler.CrossOriginHandler"> | ||
<Set name="allowCredentials"> | ||
<Property name="jetty.crossorigin.allowCredentials" default="true" /> | ||
</Set> | ||
<Call name="setAllowedHeaders"> | ||
<Arg type="Set"> | ||
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit"> | ||
<Arg> | ||
<Property name="jetty.crossorigin.allowedHeaders" default="Content-Type" /> | ||
</Arg> | ||
</Call> | ||
</Arg> | ||
</Call> | ||
<Call name="setAllowedMethods"> | ||
<Arg type="Set"> | ||
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit"> | ||
<Arg> | ||
<Property name="jetty.crossorigin.allowedMethods" default="GET,POST,HEAD" /> | ||
</Arg> | ||
</Call> | ||
</Arg> | ||
</Call> | ||
<Call name="setAllowedOriginPatterns"> | ||
<Arg type="Set"> | ||
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit"> | ||
<Arg> | ||
<Property name="jetty.crossorigin.allowedOriginPatterns" default="*" /> | ||
</Arg> | ||
</Call> | ||
</Arg> | ||
</Call> | ||
<Call name="setAllowedTimingOriginPatterns"> | ||
<Arg type="Set"> | ||
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit"> | ||
<Arg> | ||
<Property name="jetty.crossorigin.allowedTimingOriginPatterns" default="" /> | ||
</Arg> | ||
</Call> | ||
</Arg> | ||
</Call> | ||
<Set name="deliverPreflightRequests" property="jetty.crossorigin.deliverPreflightRequests" /> | ||
<Set name="deliverNonAllowedOriginRequests" property="jetty.crossorigin.deliverNonAllowedOriginRequests" /> | ||
<Set name="deliverNonAllowedOriginWebSocketUpgradeRequests" property="jetty.crossorigin.deliverNonAllowedOriginWebSocketUpgradeRequests" /> | ||
<Call name="setExposedHeaders"> | ||
<Arg type="Set"> | ||
<Call class="org.eclipse.jetty.util.StringUtil" name="csvSplit"> | ||
<Arg> | ||
<Property name="jetty.crossorigin.exposedHeaders" default="" /> | ||
</Arg> | ||
</Call> | ||
</Arg> | ||
</Call> | ||
<Call name="setPreflightMaxAge"> | ||
<Arg> | ||
<Call class="java.time.Duration" name="ofSeconds"> | ||
<Arg type="long"> | ||
<Property name="jetty.crossorigin.preflightMaxAge" default="60" /> | ||
</Arg> | ||
</Call> | ||
</Arg> | ||
</Call> | ||
</New> | ||
</Arg> | ||
</Call> | ||
</Configure> |
48 changes: 48 additions & 0 deletions
48
jetty-core/jetty-server/src/main/config/modules/cross-origin.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# DO NOT EDIT THIS FILE - See: https://eclipse.dev/jetty/documentation/ | ||
|
||
[description] | ||
Enables CrossOriginHandler to support the CORS protocol and protect from cross-site request forgery (CSRF) attacks. | ||
|
||
[tags] | ||
server | ||
handler | ||
csrf | ||
|
||
[depend] | ||
server | ||
|
||
[xml] | ||
etc/jetty-cross-origin.xml | ||
|
||
[ini-template] | ||
#tag::documentation[] | ||
## Whether cross-origin requests can include credentials such as cookies or authentication headers. | ||
# jetty.crossorigin.allowCredentials=true | ||
|
||
## A comma-separated list of headers allowed in cross-origin requests. | ||
# jetty.crossorigin.allowedHeaders=Content-Type | ||
|
||
## A comma-separated list of HTTP methods allowed in cross-origin requests. | ||
# jetty.crossorigin.allowedMethods=GET,POST,HEAD | ||
|
||
## A comma-separated list of origins regex patterns allowed in cross-origin requests. | ||
# jetty.crossorigin.allowedOriginPatterns=* | ||
|
||
## A comma-separated list of timing origins regex patterns allowed in cross-origin requests. | ||
# jetty.crossorigin.allowedTimingOriginPatterns= | ||
|
||
## Whether preflight requests are delivered to the child Handler of CrossOriginHandler. | ||
# jetty.crossorigin.deliverPreflightRequests=false | ||
|
||
## Whether requests whose origin is not allowed are delivered to the child Handler of CrossOriginHandler. | ||
# jetty.crossorigin.deliverNonAllowedOriginRequests=true | ||
|
||
## Whether WebSocket upgrade requests whose origin is not allowed are delivered to the child Handler of CrossOriginHandler. | ||
# jetty.crossorigin.deliverNonAllowedOriginWebSocketUpgradeRequests=false | ||
|
||
## A comma-separated list of headers allowed in cross-origin responses. | ||
# jetty.crossorigin.exposedHeaders= | ||
|
||
## How long the preflight results can be cached by browsers, in seconds. | ||
# jetty.crossorigin.preflightMaxAge=60 | ||
#end::documentation[] |
Oops, something went wrong.