Skip to content

Reapply "CspNonce changes"#2598

Merged
delbarrow merged 5 commits intomainfrom
feature/Li-144483-v2
Feb 25, 2026
Merged

Reapply "CspNonce changes"#2598
delbarrow merged 5 commits intomainfrom
feature/Li-144483-v2

Conversation

@Vishala230531
Copy link
Contributor

Description
Fix CSP Nonce Handling for Venmo QR Code Component
https://paypal.atlassian.net/browse/LI-144483

Problem

When merchants use v5 of the JS SDK with a Content-Security-Policy that includes a [style-src] directive with a nonce, the Venmo QR code modal fails to render correctly in production environments. The issue occurs because:

Merchant provides CSP nonce to JS SDK via [data-csp-nonce] attribute
When buyer clicks Venmo button on desktop, QR code flow is triggered
The QR code component injects inline CSS without the proper nonce
Browser rejects the CSS due to CSP violation
QR code modal renders incorrectly (styling broken)

Root Cause
The QR code component was inconsistently handling CSP nonces:

Component relied on [props.cspNonce] which wasn't always properly propagated
In server-side rendering contexts, nonce values weren't being passed through props correctly
Container and prerender templates weren't getting the nonce needed for inline styles

Solution
Implemented consistent CSP nonce handling across all QR code component files:

Component Configuration
([component.jsx]
Changed [cspNonce] prop to [default: WEB ? getCSPNonce : () => undefined]
Ensures fallback when props don't contain nonce

Container Template
([container.jsx]
Now directly calls [getCSPNonce()] instead of using [props.cspNonce

Prerender Template ([prerender.jsx]
Updated to get CSP nonce directly from SDK client
Applies nonce to both inline styles and SpinnerPage component

Environment Safety
Added [WEB] checks to prevent server-side rendering issues
Returns undefined in non-web environments
Testing
✅ Verified QR code modal renders correctly with CSP nonces
✅ No CSP violations in browser console
Before:
Screenshot 2026-02-20 at 11 52 53 AM

After

Screenshot 2026-02-20 at 1 49 20 PM

This reverts commit 934fd82.
@Vishala230531 Vishala230531 requested a review from a team as a code owner February 20, 2026 19:49
Copy link
Contributor

@delbarrow delbarrow left a comment

Choose a reason for hiding this comment

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

Great work debugging this!!!

Copy link
Contributor

@nikrom17 nikrom17 left a comment

Choose a reason for hiding this comment

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

Can we add some unit tests please?

@delbarrow delbarrow requested a review from nikrom17 February 24, 2026 00:01
@delbarrow delbarrow merged commit 2c7106b into main Feb 25, 2026
4 checks passed
@delbarrow delbarrow deleted the feature/Li-144483-v2 branch February 25, 2026 02:34
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.

3 participants