Skip to content
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

Add report to header config #30

Merged
merged 7 commits into from
Jun 29, 2022
Merged

Add report to header config #30

merged 7 commits into from
Jun 29, 2022

Conversation

peterMuriuki
Copy link
Collaborator

Add report to header config

.env.sample Outdated Show resolved Hide resolved
src/app/index.ts Show resolved Hide resolved
src/app/index.ts Outdated Show resolved Hide resolved
src/app/index.ts Outdated Show resolved Hide resolved
src/app/index.ts Outdated
app.use(
helmet({
// override default contentSecurityPolicy directive like script-src to include cloudflare cdn and github static content
// might consider turning this off to allow individual front-ends set Content-Security-Policy on meta tags themselves if list grows long
// <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com;" >
contentSecurityPolicy: {
directives: EXPRESS_CONTENT_SECURITY_POLICY_CONFIG,
reportOnly: !!reportOnly,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a 'danger' to using this header IMO. If it's accidentally set to true it negates all the benefits of csp (Content-Security-Policy-Report-Only header is set instead of Content-Security-Policy). At the very worst both csp headers should co-exist (i.e Content-Security-Policy and Content-Security-Policy-Report-Only). I would vote to have this directive removed (defaults to false) or to set both as described here helmetjs/helmet#351 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, I will remove the reportOnly for now, I think we can use the more general express_reponse_headers to append other headers including the report-only variant

.env.sample Outdated
EXPRESS_CONTENT_SECURITY_POLICY_CONFIG=`{"default-src":["'self'"]}`
EXPRESS_CONTENT_SECURITY_POLICY_CONFIG=`{"default-src":["'self'"], report-only: true}`
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/report-to. `Map<string, stringifiedJson>`.
EXPRESS_RESPONSE_HEADERS='{"Report-To":"{ \"group\": \"csp-endpoint\", \"max_age\": 10886400, \"endpoints\": [{ \"url\": \"https://example.com/endpoint\" }] }"}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an example second response header to show how to pass multiple headers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also is the Report-To key case sensitive?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, Header fields are not case sensitive

src/app/index.ts Outdated
const customHeaders = Object.entries(EXPRESS_RESPONSE_HEADERS);
if (customHeaders.length > 0) {
customHeaders.forEach(([key, value]) => {
if (typeof value === 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we also want to check if value !== ""?

@peterMuriuki peterMuriuki merged commit 80fd0e6 into master Jun 29, 2022
@peterMuriuki peterMuriuki deleted the report-to-header branch June 29, 2022 07:01
peterMuriuki pushed a commit that referenced this pull request Feb 20, 2024
* Add flag to enable/disable CQL to JSON strict mode validation

* Upgrade dependencies

* Release version bump to 2.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants