Skip to content

Commit

Permalink
rename html integrity re to general as this replaces both html and ja…
Browse files Browse the repository at this point in the history
…vascript integrity tags in certain cases
  • Loading branch information
AtofStryker committed Sep 19, 2022
1 parent 505fa80 commit 700c75e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/proxy/lib/http/util/regex-rewriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const javaScriptIntegrityReplacementRe = new RegExp(`[\\.](${STRIPPED_INTEGRITY_
* but the match only starts at the word integrity, and not the character preceding it. In these cases, we always replace the word integrity with cypress-stripped-integrity.
* The match for cypress-stripped-integrity is if we are replacing in the stripStream, and the replaced text is rematched no essentially complete a no op
*/
const htmlIntegrityReplacementRe = new RegExp(`(?:(?<!(var|let|nst)\\s)[^\\.\\s'"]?)(${STRIPPED_INTEGRITY_TAG}|integrity)((?:'|")?\\]?(\\s?=|["|'],)\\s?(?:"|')sha(?:256|384|512)-.*?(?:"|'))`, 'g')
const generalIntegrityReplacementRe = new RegExp(`(?:(?<!(var|let|nst)\\s)[^\\.\\s'"]?)(${STRIPPED_INTEGRITY_TAG}|integrity)((?:'|")?\\]?(\\s?=|["|'],)\\s?(?:"|')sha(?:256|384|512)-.*?(?:"|'))`, 'g')

export function strip (html: string, { modifyObstructiveThirdPartyCode }: Partial<SecurityOpts> = {
modifyObstructiveThirdPartyCode: false,
Expand All @@ -41,7 +41,7 @@ export function strip (html: string, { modifyObstructiveThirdPartyCode }: Partia

if (modifyObstructiveThirdPartyCode) {
rewrittenHTML = rewrittenHTML.replace(javaScriptIntegrityReplacementRe, `['${STRIPPED_INTEGRITY_TAG}']$2`)
rewrittenHTML = rewrittenHTML.replace(htmlIntegrityReplacementRe, `${STRIPPED_INTEGRITY_TAG}$3`)
rewrittenHTML = rewrittenHTML.replace(generalIntegrityReplacementRe, `${STRIPPED_INTEGRITY_TAG}$3`)
}

return rewrittenHTML
Expand All @@ -61,7 +61,7 @@ export function stripStream ({ modifyObstructiveThirdPartyCode }: Partial<Securi
jiraTopWindowGetterUnMinifiedRe,
...(modifyObstructiveThirdPartyCode ? [
javaScriptIntegrityReplacementRe,
htmlIntegrityReplacementRe,
generalIntegrityReplacementRe,
] : []),
],
[
Expand Down

0 comments on commit 700c75e

Please sign in to comment.