|
| 1 | +# CSP Fix Plan - Systematic Approach |
| 2 | + |
| 3 | +## Problem |
| 4 | +58 CSP violations from inline styles in `index-*.js:10`. We've removed react-bootstrap but violations persist. |
| 5 | + |
| 6 | +## Root Cause Analysis Plan |
| 7 | + |
| 8 | +### Step 1: Identify the Source |
| 9 | +The errors point to `index-Bf2rhuza.js:10`. We need to: |
| 10 | +1. **Build locally and inspect the bundle** |
| 11 | + - Build: `cd frontend && npm run build` |
| 12 | + - Search the built JS file for `.style` or `setProperty` calls |
| 13 | + - Identify which library/component is generating inline styles |
| 14 | + |
| 15 | +### Step 2: Likely Culprits (Priority Order) |
| 16 | + |
| 17 | +#### A. react-aria-components |
| 18 | +- **Why**: Used by BCGov design-system, known to use inline styles |
| 19 | +- **Check**: Search for `style=` or `style.setProperty` in react-aria-components source |
| 20 | +- **Fix**: If confirmed, we need to either: |
| 21 | + - Patch react-aria-components to not use inline styles |
| 22 | + - Find a CSP-compliant alternative |
| 23 | + - Use a CSP proxy/interceptor to convert inline styles to classes |
| 24 | + |
| 25 | +#### B. BCGov Design System Components |
| 26 | +- **Why**: Header/Footer might internally use components that inject styles |
| 27 | +- **Check**: Inspect the built BCGov bundle for inline style usage |
| 28 | +- **Fix**: Work with BCGov team or patch the fork |
| 29 | + |
| 30 | +#### C. Bootstrap JavaScript (if we're using it) |
| 31 | +- **Why**: Bootstrap JS sometimes injects inline styles for modals/tooltips |
| 32 | +- **Check**: We're NOT importing Bootstrap JS (good!), but verify |
| 33 | +- **Fix**: Not applicable (we don't use Bootstrap JS) |
| 34 | + |
| 35 | +### Step 3: Immediate Diagnostic Actions |
| 36 | + |
| 37 | +1. **Create a minimal test page** without BCGov components |
| 38 | + - Temporarily remove Header/Footer |
| 39 | + - Check if violations go away |
| 40 | + - This isolates whether BCGov components are the source |
| 41 | + |
| 42 | +2. **Build and inspect the bundle** |
| 43 | + - Run: `cd frontend && npm run build` |
| 44 | + - Open `dist/index-*.js` in editor |
| 45 | + - Search for: `style=`, `.style`, `setProperty`, `style-src` |
| 46 | + - Look at line 10 or nearby for style manipulation |
| 47 | + |
| 48 | +3. **Browser console inspection** |
| 49 | + - Open the deployed site |
| 50 | + - In console, expand one of the CSP errors |
| 51 | + - Click the file link to see source mapping |
| 52 | + - Identify the actual component/library causing it |
| 53 | + |
| 54 | +### Step 4: Fix Strategy |
| 55 | + |
| 56 | +#### Option A: If react-aria-components is the problem |
| 57 | +1. Create a Vite plugin to intercept and convert inline styles to CSS classes |
| 58 | +2. OR: Fork/patch react-aria-components to not use inline styles |
| 59 | +3. OR: Replace BCGov components that use react-aria-components |
| 60 | + |
| 61 | +#### Option B: If BCGov components are the problem |
| 62 | +1. Check our fork - are we using the right branch? |
| 63 | +2. Inspect the built BCGov bundle in `/tmp/bcgov-design-system/packages/react-components/dist/` |
| 64 | +3. Search for inline style usage |
| 65 | +4. Fix in our fork and test |
| 66 | + |
| 67 | +#### Option C: Runtime style interceptor (temporary) |
| 68 | +1. Create a script that runs before React renders |
| 69 | +2. Intercepts `element.style.setProperty` calls |
| 70 | +3. Converts them to CSS classes dynamically |
| 71 | +4. This is a workaround, not a permanent fix |
| 72 | + |
| 73 | +## Next Immediate Steps |
| 74 | + |
| 75 | +1. **Build locally and inspect** |
| 76 | + ```bash |
| 77 | + cd frontend |
| 78 | + npm run build |
| 79 | + grep -r "\.style\|setProperty" dist/ |
| 80 | + ``` |
| 81 | + |
| 82 | +2. **Create minimal test** - Remove Header/Footer temporarily to isolate |
| 83 | + |
| 84 | +3. **Check browser source maps** - Use devtools to find exact source |
| 85 | + |
| 86 | +4. **Report findings** - Once we identify the source, we can fix it properly |
| 87 | + |
0 commit comments