Directives can only be added in kebab case
See original GitHub issueWhen using the default directives as a starting point, it’s not possible to specify other directives in camel case, only in kebab case. In other words, the following code works fine:
const express = require('express')
const helmet = require('helmet')
const app = express()
const PORT = 3000
app.use(helmet.contentSecurityPolicy({
directives: {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
'script-src': ["'self'", "example.com"]
}
}))
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(PORT, () => {
console.log(`Example app listening at http://localhost:${PORT}`)
})
I’ve checked the Content-Security-Policy
header, which correctly includes script-src 'self' example.com;
. However, if I change 'script-src'
to scriptSrc
, I get the following error:
throw new Error(`Content-Security-Policy received a duplicate directive ${JSON.stringify(directiveName)}`);
^
Error: Content-Security-Policy received a duplicate directive "script-src"
While the workaround for this issue is easy (just use kebab case), it is inconsistent that these methods do not give the same result. I propose that either both methods throw an error or both just add the directive to the default directives (which is the preferred option in my opinion).
I’m using express 4.17.1, helmet 4.3.1, and node 14.15.1.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
kebab-case option warns of single words in component-selector
While creating the docs for the rule component-selector, I found an error message different from what I expected. Expected message.
Read more >Bind to @Input alias where directive is kebab-case
I am attempting to use kebab-case in my directive and camelCase as my alias. Something like. my-component.html
Read more >Angular CLI: camelCase or kebab-case - JavaScript inDepth
Just for fun, let's take a quick survey of the differences between camel case and kebab case and where they are typically used...
Read more >Angular directives | decorator | Attributes | Structural - Medium
Suppose we want to create a directive that represents an input form field. Here are some specifications: Our target is only text input...
Read more >Glossary | AngularDart Community Documentation
The practice of writing compound words or phrases such that each word is separated by a dash or hyphen ( - ). This...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You make a good point. I agree that option 4 makes the most sense and that a
useDefaults
setting which is disabled by default in helmet 4 and enabled by default in version 5 seems to be the most intuitive.The
useDefaults
option was added tohelmet@4.6.0
andhelmet-csp@3.4.0
.The option defaults to
false
, but that will change totrue
in the next major version. You can see that work tracked in #314 and follow along with all of Helmet v5 in #309. (Help is wanted on a number of these issues!)