Skip to content

Commit afd83d0

Browse files
author
Vincent Dubois
committed
Replace the nonce in development key
1 parent f98c837 commit afd83d0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/lib/csp-proxy/CspProxy.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const replaceNoncePlaceholder = (
3030
placeholder: string,
3131
nonceValue: string,
3232
): string => {
33-
return initialValue.replaceAll(placeholder, `${nonceValue}`);
33+
return initialValue.replaceAll(placeholder, nonceValue);
3434
};
3535

3636
/**
@@ -116,11 +116,14 @@ export function configureCspProxyServer<Environment extends string = never>(
116116
response.locals.cspNonce = nonce;
117117
}
118118

119+
// If there is a nonce configuration, replace the placeholder by the generated value
120+
const computedRules: CspPolicies<Environment> = !!noncesConfiguration
121+
? computeRulesWithNonce<Environment>(rules, nonce, noncesConfiguration.nonceTemplate, noncesConfiguration.developmentKey)
122+
: rules;
123+
119124
// Process the rules to replace the nonce placeholder placeholders with the generated nonce if template is provided
120125
const directives: string = computeCspDirectiveForEnvironment<Environment>(
121-
!!noncesConfiguration
122-
? computeRulesWithNonce(rules, nonce, noncesConfiguration.nonceTemplate)
123-
: rules,
126+
computedRules,
124127
noncesConfiguration?.developmentKey,
125128
);
126129

0 commit comments

Comments
 (0)