-
Notifications
You must be signed in to change notification settings - Fork 41
Add new output callback function #44
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
|
b41857a
to
2a245bf
Compare
Codecov Report
@@ Coverage Diff @@
## master #44 +/- ##
===========================================
- Coverage 93.85% 77.77% -16.09%
===========================================
Files 2 2
Lines 114 117 +3
Branches 22 23 +1
===========================================
- Hits 107 91 -16
- Misses 6 23 +17
- Partials 1 3 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #44 +/- ##
===========================================
- Coverage 93.85% 77.22% -16.64%
===========================================
Files 2 2
Lines 114 180 +66
Branches 22 42 +20
===========================================
+ Hits 107 139 +32
- Misses 6 37 +31
- Partials 1 4 +3
Continue to review full report at Codecov.
|
Thanks for your submission! Unfortunately, this is not currently a feature we're looking to add, so I'm going to close this PR. |
@AnujRNair Would you guys consider a PR for a hook that would let other plugins make use of |
@bcanseco sure, let's chat about it! There are a few routes we could go down here, I'm interested in your use case. Are you looking to:
Let me know, and we can discuss some implementation details! |
@AnujRNair I think my ultimate goal is the latter: to use the policy outside of webpack. Specifically inside an nginx configuration file (here's what I'm currently doing with @fcsonline's branch) There's probably more elegant ways to go about it, but I think some kind of callback would work the best. Whether that be a new option like proposed in this PR or perhaps some way to get access to the policy from the new CspHtmlWebpackPlugin(defaultPolicy, {
enabled: (htmlPluginData, buildPolicy) => {
const policy = buildPolicy();
/* do stuff with the policy */
return false;
};
}); or... new CspHtmlWebpackPlugin(defaultPolicy, {
enabled: (htmlPluginData) => {
const {policy} = htmlPluginData;
/* do stuff with the policy */
return false;
};
}); |
Our team is doing something similar. We output the generated CSP rule to a plaintext file and we add a dynamic header in Nginx with a small Lua script. With this, we achieve all the benefits of CSP without the requirement of a full dynamic server. The original pull request was designed to be opt-in, so developers with this requirement can tweak the webpack configuration to achieve it. |
@bcanseco @fcsonline I created a pull request with the ability to overwrite the default processing function in #58 Would appreciate your reviews and thought there! |
Reviewed! It looks good! 👌 |
Summary
Adding a new
output
callback function passing the computed CSP rules to execute custom logic.Our team is interested to add CSP policy, but we want to add it as HTTP header instead of
meta
tag. This enables the capability to useframe-ancestors
, report-uri, orsandbox
not available withmeta
tag.Right now, the rule is automatically added as
meta
tag. To be able to add it as HTTP header, we need to compute the rule bycsp-html-webpack-plugin
and pass it to a custom function to use it for example by Nginx.Requirements (place an
x
in each[ ]
)