Skip to content

Commit

Permalink
Feature/cors (#263) (#264)
Browse files Browse the repository at this point in the history
* Update properties

* Upgrade GHA to use Node.js 20

* Improve handling attributes in firewall

* Modify SecurityConfig to use CORS config from property file

* Fix wss ssl

* Update pom.xml to use latest MMP

* Update CHANGELOG.md and README.md

* Address PR comments

* Update test to check PUT method, since OPTIONS is now allowed in
Firewall

Co-authored-by: Igor Balog Eng <[email protected]>
  • Loading branch information
marest94 and IgorBalog-Eng authored Jul 11, 2024
1 parent fc42ddf commit f2d53d7
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 181 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/ECC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand All @@ -40,7 +40,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -252,7 +252,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -286,7 +286,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -320,7 +320,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -354,7 +354,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down Expand Up @@ -388,7 +388,7 @@ jobs:
TRUSTSTORE_PASSWORD_DOCKER: ${{secrets.TRUSTSTORE_PASSWORD_DOCKER}}
steps:
- name: Git Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run env setup
run: ./ci/setupEnv.sh
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
if: "!contains(github.event.head_commit.message, '[maven-release-plugin]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.14.9] - 2024-07-11

### Added

- CORS configuration (for compatibility with UI)

### Changed

- Updated firewall.properties
- Multipart message library upgraded to 1.0.18
- Websocket library upgraded to 1.0.18
- Fix WSS SSL support
- Upgrade GHA to use Node.js 20


## [1.14.8] - 2024-02-14

### Added
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ allowUrlEncodedPeriod=true
```
*IMPORTANT:* If you're not an expert, the strong advice is to keep values at their default values. If you decide to change values, pay special attention to allowHeaderNames and allowHeaderValues, since those set values are exclusive and considered as only values that should be present in the header.

## CORS Configuration

In order to communicate with UI, CORS (Cross-Origin Resource Sharing) settings should be configured in `application.properties` file. This allows you to specify which origins, methods, and headers are permitted when making cross-origin requests to your application.

```
application.cors.allowed.origins=
application.cors.allowed.methods=
application.cors.allowed.headers=
```

- `application.cors.allowed.origins`: Specifies the allowed origins. If empty, all origins (*) are allowed.
- `application.cors.allowed.methods`: Specifies the allowed HTTP methods. If empty, all methods (*) are allowed.
- `application.cors.allowed.header`s: Specifies the allowed headers. If empty, all headers (*) are allowed.

Example configuration:

```
# Allow specific origins
application.cors.allowed.origins=https://example.com,https://another-example.com
# Allow specific HTTP methods
application.cors.allowed.methods=GET,POST,PUT,DELETE
# Allow specific headers
application.cors.allowed.headers=
```



## How to Test
The reachability could be verified using the following endpoints:
* **http://{IP_ADDRESS}:{HTTP_PUBLIC_PORT}/about/version**
Expand Down
8 changes: 8 additions & 0 deletions ci/docker/be-dataapp_resources/application-docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ application.security.password=$2a$10$MQ5grDaIqDpBjMlG78PFduv.AMRe9cs0CNm/V4cgUub

#checkSum verification - true | false
application.verifyCheckSum=false

#CORS configuration
#Allow specific origins
application.cors.allowed.origins=
#Allow specific HTTP methods
application.cors.allowed.methods=
#Allow specific headers
application.cors.allowed.headers=
2 changes: 1 addition & 1 deletion ci/docker/be-dataapp_resources/firewall.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ allowedHeaderNames=
#Set which values in header names should have the exact value and allowed (if want to allow any values keep it empty)
allowedHeaderValues=
#Set which HTTP methods should be allowed (if want to allow all header names, keep it empty)
allowedMethods=GET,POST
allowedMethods=GET,POST,OPTIONS
#Set if a backslash "\" or a URL encoded backslash "%5C" should be allowed in the path or not
allowBackSlash=true
#Set if a slash "/" that is URL encoded "%2F" should be allowed in the path or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,13 @@ spring.h2.console.enabled=true
spring.datasource.username=sa
spring.datasource.password=file_password password

#CORS configuration
#Allow specific origins
application.cors.allowed.origins=
#Allow specific HTTP methods
application.cors.allowed.methods=
#Allow specific headers
application.cors.allowed.headers=

#For logging the response over WSS set to DEBUG, else leave empty
#logging.level.it.eng.idsa.businesslogic.processor.receiver=
2 changes: 1 addition & 1 deletion ci/docker/ecc_resources_consumer/firewall.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ allowedHeaderNames=
#Set which values in header names should have the exact value and allowed (if want to allow any values keep it empty)
allowedHeaderValues=
#Set which HTTP methods should be allowed (if want to allow all header names, keep it empty)
allowedMethods=GET,POST
allowedMethods=GET,POST,OPTIONS
#Set if a backslash "\" or a URL encoded backslash "%5C" should be allowed in the path or not
allowBackSlash=true
#Set if a slash "/" that is URL encoded "%2F" should be allowed in the path or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,13 @@ spring.h2.console.enabled=true
spring.datasource.username=sa
spring.datasource.password=file_password password

#CORS configuration
#Allow specific origins
application.cors.allowed.origins=
#Allow specific HTTP methods
application.cors.allowed.methods=
#Allow specific headers
application.cors.allowed.headers=

#For logging the response over WSS set to DEBUG, else leave empty
#logging.level.it.eng.idsa.businesslogic.processor.receiver=
2 changes: 1 addition & 1 deletion ci/docker/ecc_resources_provider/firewall.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ allowedHeaderNames=
#Set which values in header names should have the exact value and allowed (if want to allow any values keep it empty)
allowedHeaderValues=
#Set which HTTP methods should be allowed (if want to allow all header names, keep it empty)
allowedMethods=GET,POST
allowedMethods=GET,POST,OPTIONS
#Set if a backslash "\" or a URL encoded backslash "%5C" should be allowed in the path or not
allowBackSlash=true
#Set if a slash "/" that is URL encoded "%2F" should be allowed in the path or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
}
]
},
"method": "OPTIONS",
"method": "PUT",
"header": [
{
"key": "fizz",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<camel.version>3.19.0</camel.version>
<tomcat.version>9.0.76</tomcat.version>
<application.basedir>${basedir}</application.basedir>
<multipart.message.processor.version>1.0.17</multipart.message.processor.version>
<multipart.message.processor.version>1.0.18</multipart.message.processor.version>
<idscp2.libraries.version>0.5.2</idscp2.libraries.version>
<jacoco.version>0.8.8</jacoco.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public class EccFirewall {
private boolean allowUrlEncodedPercent;
@Value("${allowUrlEncodedPeriod}")
private boolean allowUrlEncodedPeriod;

@Bean
@ConditionalOnProperty(name = "application.firewall.isEnabled", havingValue = "true", matchIfMissing = false)
RequestRejectedHandler requestRejectedHandler() {
return new HttpStatusRequestRejectedHandler(HttpStatus.METHOD_NOT_ALLOWED.value());
return new HttpStatusRequestRejectedHandler(HttpStatus.METHOD_NOT_ALLOWED.value());
}

@Bean
Expand All @@ -53,13 +53,19 @@ public StrictHttpFirewall httpFirewall() {
if (!CollectionUtils.isEmpty(allowedHeaderNames)) {
Predicate<String> headerNamePredicate = createAllowedHeaderNamesPredicate(allowedHeaderNames);
firewall.setAllowedHeaderNames(headerNamePredicate);
} else {
firewall.setAllowedHeaderNames((header) -> true);
}
if (!allowedHeaderValues.isEmpty()) {
Predicate<String> headerNameValuePredicate = createAllowedHeaderValuesPredicate(allowedHeaderValues);
firewall.setAllowedHeaderValues(headerNameValuePredicate);
} else {
firewall.setAllowedHeaderValues((header) -> true);
}
if (!CollectionUtils.isEmpty(allowedMethods)) {
firewall.setAllowedHttpMethods(allowedMethods);
} else {
firewall.setUnsafeAllowAnyHttpMethod(true);
}
firewall.setAllowBackSlash(allowBackSlash);
firewall.setAllowUrlEncodedSlash(allowUrlEncodedSlash);
Expand All @@ -70,7 +76,7 @@ public StrictHttpFirewall httpFirewall() {

return firewall;
}

private Predicate<String> createAllowedHeaderNamesPredicate(List<String> allowedHeaderNames) {
return allowedHeaderNames.stream().collect(Collectors.toSet())::contains;
}
Expand Down
Loading

0 comments on commit f2d53d7

Please sign in to comment.