-
Notifications
You must be signed in to change notification settings - Fork 258
KNOX-3124 - Add Security Header filter to WebAppSec Provider #1021
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
base: master
Are you sure you want to change the base?
Conversation
@@ -55,6 +55,10 @@ public class WebAppSecContributor extends ProviderDeploymentContributorBase { | |||
private static final String RATE_LIMITING_PREFIX = "rate.limiting"; | |||
private static final String RATE_LIMITING_SUFFIX = "_RATE.LIMITING"; | |||
private static final String RATE_LIMITING_ENABLED = RATE_LIMITING_PREFIX + ".enabled"; | |||
private static final String SECURITY_HEADER_PREFIX = "security.header"; |
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 the prefix should be "security.header."
(note the .
at the end).
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 agree but others are this way too just keeping it consistent.
|
||
public class SecurityHeaderFilter implements Filter { | ||
|
||
private Map<String, String> map = new HashMap<>(); |
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.
A better class member name would be more helpful.
Enumeration<String> initParamNames = filterConfig.getInitParameterNames(); | ||
while (initParamNames.hasMoreElements()) { | ||
String headerName = initParamNames.nextElement(); | ||
if (!"enabled".equals(headerName)) { |
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 may want to create another constant for enabled
in WebAppSeciContributor and re-use it here.
|
||
@Override | ||
public void addHeader(String name, String value) { | ||
if (!"enabled".equals(name)) { |
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.
See my recommendation above of using a constant here.
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.
LGTM
What changes were proposed in this pull request?
In order to add various security headers to a response, we can add a generic filter for which init params with the param name and value indicating the header name and string representing the directives for the header respectively.
This will allow admins to configure things like Content-Security-Policy, Cache-Control, etc. without the need to add separate filters for each one.
How was this patch tested?
New unit tests were added.
All new and existing tests were run.
Manual testing was done with the following web app sec provider config and curl command:
Note the params with the "security.header." prefix and the headers added to the resulting output from the curl command below: