-
Notifications
You must be signed in to change notification settings - Fork 7
Add configuration for allowing http connection during development #81
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
Open
svenzik
wants to merge
6
commits into
main
Choose a base branch
from
WE2-967-allow-http
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f67b9a2
Add configuration for allowing http connection during development
svenzik a36a935
Cookie name prefix __Host- is added only when https is used
svenzik 8766b6f
Fix log statement to be clear what configuration option is replaced
svenzik 3793c68
Fix ipv6 format
svenzik 6ac5a34
Test for long localhost format [0000:0000:0000:0000:0000:0000:0000:0001]
svenzik 8c34c66
example: bump version to 3.2.1-SNAPSHOT
mrts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| spring.profiles.active=dev | ||
| server.servlet.session.cookie.name=__Host-JSESSIONID |
28 changes: 28 additions & 0 deletions
28
example/src/test/java/eu/webeid/example/config/CookieHttpTest.java
This file contains hidden or 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,28 @@ | ||
| package eu.webeid.example.config; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import jakarta.servlet.ServletContext; | ||
| import jakarta.servlet.SessionCookieConfig; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
| import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; | ||
| import org.springframework.test.context.TestPropertySource; | ||
|
|
||
| @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
| @TestPropertySource(properties = {"web-eid-auth-token.validation.local-origin=http://localhost"}) | ||
| class CookieHttpTest { | ||
|
|
||
| @Autowired | ||
| private ServletWebServerApplicationContext context; | ||
|
|
||
| @Test | ||
| void whenLocalOriginStartsWithHttp_thenCookeDoesNotHaveHostPrefix() { | ||
| ServletContext servletContext = context.getServletContext(); | ||
| SessionCookieConfig cookieConfig = servletContext.getSessionCookieConfig(); | ||
| assertThat(cookieConfig.getName()).isEqualTo("JSESSIONID"); | ||
| } | ||
|
|
||
| } |
28 changes: 28 additions & 0 deletions
28
example/src/test/java/eu/webeid/example/config/CookieHttpsTest.java
This file contains hidden or 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,28 @@ | ||
| package eu.webeid.example.config; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import jakarta.servlet.ServletContext; | ||
| import jakarta.servlet.SessionCookieConfig; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
| import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; | ||
| import org.springframework.test.context.TestPropertySource; | ||
|
|
||
| @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
| @TestPropertySource(properties = {"web-eid-auth-token.validation.local-origin=https://localhost"}) | ||
| class CookieHttpsTest { | ||
|
|
||
| @Autowired | ||
| private ServletWebServerApplicationContext context; | ||
|
|
||
| @Test | ||
| void whenLocalOriginStartsWithHttp_thenCookeDoesNotHaveHostPrefix() { | ||
| ServletContext servletContext = context.getServletContext(); | ||
| SessionCookieConfig cookieConfig = servletContext.getSessionCookieConfig(); | ||
| assertThat(cookieConfig.getName()).isEqualTo("__Host-JSESSIONID"); | ||
| } | ||
|
|
||
| } |
73 changes: 73 additions & 0 deletions
73
example/src/test/java/eu/webeid/example/config/YAMLConfigTest.java
This file contains hidden or 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,73 @@ | ||
| package eu.webeid.example.config; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| class YAMLConfigTest { | ||
|
|
||
| @ValueSource(strings = { | ||
| "http://localhost", | ||
| "http://localhost:8080", | ||
| "http://127.0.0.1", | ||
| "http://127.0.0.1:8080", | ||
| "http://[::1]", | ||
| "http://[::1]:8080", | ||
| "http://[0000:0000:0000:0000:0000:0000:0000:0001]", | ||
| "http://[0000:0000:0000:0000:0000:0000:0000:0001]:8080" | ||
| }) | ||
| @ParameterizedTest | ||
| void givenLocalOriginHttpLoopbackAddress_whenParsingLocalOrigin_thenItIsReplacedWithHttps(String origin) { | ||
| YAMLConfig yamlConfig = new YAMLConfig(); | ||
| yamlConfig.setLocalOrigin(origin); | ||
| assertThat(yamlConfig.getLocalOrigin()).isEqualTo(origin.replaceFirst("^http:", "https:")); | ||
| } | ||
|
|
||
| @ValueSource(strings = { | ||
| "https://localhost", | ||
| "https://localhost:8080", | ||
| "https://127.0.0.1", | ||
| "https://127.0.0.1:8080", | ||
| "https://[::1]", | ||
| "https://[::1]:8080", | ||
| "https://[0000:0000:0000:0000:0000:0000:0000:0001]", | ||
| "https://[0000:0000:0000:0000:0000:0000:0000:0001]:8080" | ||
| }) | ||
| @ParameterizedTest | ||
| void givenLocalOriginHttpsLoopbackAddress_whenParsingLocalOrigin_thenOriginalIsKept(String origin) { | ||
| YAMLConfig yamlConfig = new YAMLConfig(); | ||
| yamlConfig.setLocalOrigin(origin); | ||
| assertThat(yamlConfig.getLocalOrigin()).isEqualTo(origin); | ||
| } | ||
|
|
||
| @ValueSource(strings = { | ||
| "http://somename.app", | ||
| "http://somename.app:8080", | ||
| "http://8.8.8.8", | ||
| "http://8.8.8.8:8080", | ||
| "http://[2001:4860:4860::8888]", | ||
| "http://[2001:4860:4860::8888]:8080", | ||
| }) | ||
| @ParameterizedTest | ||
| void givenLocalOriginHttpNonLoopbackAddress_whenParsingLocalOrigin_thenOriginalIsKept(String origin) { | ||
| YAMLConfig yamlConfig = new YAMLConfig(); | ||
| yamlConfig.setLocalOrigin(origin); | ||
| assertThat(yamlConfig.getLocalOrigin()).isEqualTo(origin); | ||
| } | ||
|
|
||
| @ValueSource(strings = { | ||
| "https://localhost/", | ||
| "https://localhost:8080/" | ||
| }) | ||
| @ParameterizedTest | ||
| void givenLocalOriginThatEndsWithSlash_whenParsingLocalOrigin_thenExceptionIsThrown(String origin) { | ||
| YAMLConfig yamlConfig = new YAMLConfig(); | ||
| assertThatThrownBy(() -> yamlConfig.setLocalOrigin(origin)) | ||
| .hasMessage("Configuration parameter local-origin cannot end with '/': " + origin); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
I feel uneasy about doing this so directly, folks may start copy-pasting this into their code without thinking.
Can we perhaps use a special profile
enable-httpand add thorough comments to make it absolutely clear that this should not be used in production? Or am I too paranoid, do we want to assume abusing the loopback address is impossible?