Implement CSP compliance with nonce support for strict policies#718
Open
micahstubbs wants to merge 1 commit intovasturiano:masterfrom
Open
Implement CSP compliance with nonce support for strict policies#718micahstubbs wants to merge 1 commit intovasturiano:masterfrom
micahstubbs wants to merge 1 commit intovasturiano:masterfrom
Conversation
- Replace inline styles with CSS classes for default CSP compliance - Add cspNonce property for strict CSP environments - Create CSP-compliant style injection utilities - Add TypeScript definitions for new cspNonce method - Include comprehensive test example and documentation Fixes issue where library violated Content Security Policy by using inline styles, breaking functionality in security-compliant environments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Summary
Issue: The library uses inline styles that violate strict Content Security Policies (CSP)
Impact: High - Breaks tooltips and interactive features in security-compliant environments
Root Cause: Inline style usage both directly in the library and through dependencies like
float-tooltipTechnical Analysis
The issue was caused by CSP violations from inline styles:
Direct inline styles in 3d-force-graph.js:
renderer().domElement.style.cursor = nullstate.container.style.position = 'relative'Dependency inline styles from
float-tooltipusing D3's.style()methodThese violations prevented:
Solution Implemented
1. CSS Class-Based Approach (Default)
Replaced inline styles with CSS classes for CSP compliance:
2. CSP Nonce Support (Advanced)
Added a new
cspNonceproperty for strict CSP environments:3. Utility Functions
Implemented CSP-compliant styling utilities:
injectCSPCompliantStyle()- Creates style elements with nonce supportsetCSPCompliantStyle()- Applies styles using dynamic CSS classesmakeD3CSPCompliant()- Monkey-patches D3 selections for tooltip compatibilityUsage Examples
Basic Usage (CSS Classes)
Strict CSP with Nonce
TypeScript Support
New method added to the interface:
Testing & Examples
example/csp-compliance/)Benefits
Impact
Before Fix
After Fix (Default)
After Fix (With Nonce)
Deployment Notes
Fix #710