-
Notifications
You must be signed in to change notification settings - Fork 6k
Add permissionsPolicy http header #9265
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
Conversation
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.
Thanks for the PR @kris2kris!
I have left some feedback inline, mostly around the lambda DSL.
Please reach out if you have any questions.
...n/java/org/springframework/security/config/annotation/web/configurers/HeadersConfigurer.java
Outdated
Show resolved
Hide resolved
...n/java/org/springframework/security/config/annotation/web/configurers/HeadersConfigurer.java
Show resolved
Hide resolved
...n/java/org/springframework/security/config/annotation/web/configurers/HeadersConfigurer.java
Outdated
Show resolved
Hide resolved
config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java
Outdated
Show resolved
Hide resolved
...main/java/org/springframework/security/web/header/writers/PermissionsPolicyHeaderWriter.java
Outdated
Show resolved
Hide resolved
Hi @eleftherias I added a separate commit after your review. |
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.
Thanks for the updates!
I have left some more comments inline.
Please do squash the commits.
...n/java/org/springframework/security/config/annotation/web/configurers/HeadersConfigurer.java
Show resolved
Hide resolved
...main/java/org/springframework/security/web/header/writers/PermissionsPolicyHeaderWriter.java
Outdated
Show resolved
Hide resolved
...main/java/org/springframework/security/web/header/writers/PermissionsPolicyHeaderWriter.java
Outdated
Show resolved
Hide resolved
...org/springframework/security/web/server/header/PermissionsPolicyServerHttpHeadersWriter.java
Outdated
Show resolved
Hide resolved
config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java
Outdated
Show resolved
Hide resolved
config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java
Outdated
Show resolved
Hide resolved
...java/org/springframework/security/web/header/writers/PermissionsPolicyHeaderWriterTests.java
Outdated
Show resolved
Hide resolved
Hi @eleftherias, I did the requested changes. |
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.
Thanks @kris2kris!
I have left a couple more comments.
private PermissionsPolicySpec() { | ||
} | ||
|
||
private PermissionsPolicySpec(String permissionsPolicy) { |
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 believe this constructor is unused.
* Create a new instance of {@link PermissionsPolicyHeaderWriter}. | ||
*/ | ||
public PermissionsPolicyHeaderWriter() { | ||
this(""); |
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 don't think this should set the policy to "".
We want to ensure that users are configuring the policy if they are using the PermissionsPolicyHeaderWriter
.
This will allow them to create a PermissionsPolicyHeaderWriter
without specifying the policy.
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.
Ok so we should have two ways to set the Policy ? With String and with Lambda ?
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.
Yes
http
.headers()
.permissionsPolicy()
.policy("geolocation 'self'");
and
http
.headers(headers -> headers
.permissionsPolicy(permissions -> permissions
.policy("geolocation 'self'")
)
);
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.
Ok, I change constructor and add some tests to be sure everything is ok
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.
Thanks for the updates @kris2kris!
I just have one more comment.
public PermissionsPolicyConfig permissionsPolicy(String policy) { | ||
this.permissionsPolicy.writer = new PermissionsPolicyHeaderWriter(policy); | ||
return this.permissionsPolicy; | ||
} |
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 think I confused you with my previous comment. This was correct before.
public PermissionsPolicyConfig permissionsPolicy(String policy) { | |
this.permissionsPolicy.writer = new PermissionsPolicyHeaderWriter(policy); | |
return this.permissionsPolicy; | |
} | |
public PermissionsPolicyConfig permissionsPolicy() { | |
this.permissionsPolicy.writer = new PermissionsPolicyHeaderWriter(); | |
return this.permissionsPolicy; | |
} |
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.
Oh yes, it's my bad... I revert the change and update the tests
Thanks for all of your work @kris2kris! This is now merged into master. |
|
||
package org.springframework.security.config.web.server | ||
|
||
import org.springframework.security.web.server.header.ReferrerPolicyServerHttpHeadersWriter |
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.
nit: it looks like an unused import.
Pull request for issue #9262