Skip to content

Commit 6aa6114

Browse files
committed
test: add diagnostic layout without BCGov components to isolate CSP violations
- Create LayoutTest.tsx without Header/Footer from BCGov design-system - Temporarily switch __root.tsx to use LayoutTest - This will help us identify if BCGov components are the source of inline styles - If violations disappear, we know BCGov is the culprit - If violations persist, the source is elsewhere (likely react-aria-components)
1 parent a541ea6 commit 6aa6114

File tree

3 files changed

+128
-3
lines changed

3 files changed

+128
-3
lines changed

CSP_FIX_PLAN.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { FC } from 'react'
2+
// TEMPORARY: Commented out to test if BCGov components cause CSP violations
3+
// import { Footer, Header } from '@bcgov/design-system-react-components'
4+
import { Link } from '@tanstack/react-router'
5+
6+
type Props = {
7+
children: React.ReactNode
8+
}
9+
10+
const LayoutTest: FC<Props> = ({ children }) => {
11+
return (
12+
<div className="d-flex flex-column min-vh-100">
13+
{/* TEMPORARY: Simplified header to test CSP violations */}
14+
<header className="bg-dark text-white p-3">
15+
<div className="d-flex justify-content-between align-items-center">
16+
<h1 className="h5 mb-0">QuickStart OpenShift (Test Mode - No BCGov Components)</h1>
17+
<Link to="/">
18+
<button type="button" className="btn btn-light btn-sm">
19+
<i className="bi bi-house-door-fill" />
20+
</button>
21+
</Link>
22+
</div>
23+
</header>
24+
<div className="d-flex flex-grow-1 align-items-start justify-content-center mt-5 mb-5 ml-1 mr-1">
25+
{children}
26+
</div>
27+
{/* TEMPORARY: Simplified footer */}
28+
<footer className="bg-dark text-white p-3 text-center">
29+
<small>Test Footer - BCGov components removed</small>
30+
</footer>
31+
</div>
32+
)
33+
}
34+
35+
export default LayoutTest
36+

frontend/src/routes/__root.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { createRootRoute, ErrorComponent, Outlet } from '@tanstack/react-router'
2-
import Layout from '@/components/Layout'
2+
// TEMPORARY: Using LayoutTest to isolate CSP violations
3+
import LayoutTest from '@/components/LayoutTest'
4+
// import Layout from '@/components/Layout'
35
import NotFound from '@/components/NotFound'
46

57
export const Route = createRootRoute({
68
component: () => (
7-
<Layout>
9+
<LayoutTest>
810
<Outlet />
9-
</Layout>
11+
</LayoutTest>
1012
),
1113
notFoundComponent: () => <NotFound />,
1214
errorComponent: ({ error }) => <ErrorComponent error={error} />,

0 commit comments

Comments
 (0)