Skip to content

Commit

Permalink
fix(buildCSPHeaders): remove 'none' when appropriate
Browse files Browse the repository at this point in the history
The value 'none' should not be mixed with other CSP values. This change
removes the value 'none' if there is more than one value present in any
directive.
  • Loading branch information
sambauers committed Dec 20, 2022
1 parent 79c6a2a commit 3e83778
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/buildCSPHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ function getCSPDirective(value, defaultValue, mergeDefaultDirectives = false) {
// de-duplicate merged values
const uniqueValueArray = [...new Set(mergedValueArray)]

// remove value "'none'" if the array contains other values
const validValueArray = uniqueValueArray.length > 1
? uniqueValueArray.filter((v) => v !== "'none'")
: uniqueValueArray

// only return user configured values if present, otherwise return default
return uniqueValueArray.length > 0 ? uniqueValueArray : defaultValueArray
return validValueArray.length > 0 ? validValueArray : defaultValueArray
}

module.exports = function buildCSPHeaders(options = {}) {
Expand Down

0 comments on commit 3e83778

Please sign in to comment.