Skip to content

🛡️ Sentinel: Add Content Security Policy (CSP)#377

Merged
saint2706 merged 6 commits intomainfrom
sentinel-csp-10355632473291607304
Feb 14, 2026
Merged

🛡️ Sentinel: Add Content Security Policy (CSP)#377
saint2706 merged 6 commits intomainfrom
sentinel-csp-10355632473291607304

Conversation

@saint2706
Copy link
Owner

🛡️ Sentinel: [MEDIUM] Add Content Security Policy

💡 Vulnerability: The application lacked a Content Security Policy (CSP), allowing unrestricted script execution and resource loading. This increases the risk of XSS attacks executing malicious scripts or loading unauthorized resources.

🎯 Impact: An attacker could potentially inject malicious scripts (via XSS) that exfiltrate data or execute unauthorized actions.

🔧 Fix: Added a strict CSP meta tag to index.html restricting:

  • script-src: 'self', 'unsafe-eval' (required for Pyodide), 'unsafe-inline' (required for Vite HMR), and specific CDNs (cdn.jsdelivr.net).
  • connect-src: 'self', Pyodide package repos (pypi.org, files.pythonhosted.org), and HMR WebSocket (ws:).
  • worker-src: 'self', blob: (required for Pyodide workers).
  • object-src: 'none'.

Also fixed a missing type dependency issue in MarkdownRenderer.tsx by removing the explicit type import to avoid unnecessary dependencies.

✅ Verification:

  • pnpm build: Passed (verified no missing dependencies).
  • pnpm test: Passed (unit tests).
  • pnpm run test:e2e: Passed (verified app loads and functions correctly under CSP).

PR created automatically by Jules for task 10355632473291607304 started by @saint2706

- Added CSP meta tag to index.html restricting script/style/connect sources.
- Allowed specific CDNs for Pyodide execution.
- Removed explicit `hast-util-sanitize` type import in MarkdownRenderer.tsx to avoid extra dependency while maintaining type safety via structural typing.

Co-authored-by: saint2706 <45678566+saint2706@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 14, 2026 04:57
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a baseline Content Security Policy to the Vite + Pyodide client app to reduce XSS blast radius, and removes a sanitizer type import that was causing a missing type dependency problem.

Changes:

  • Add a CSP meta tag in index.html to restrict script/resource sources for the client-side app.
  • Remove the explicit Schema type import/annotation from the Markdown sanitizer schema to avoid a non-direct type dependency.
  • Reorder ESLint plugin devDependencies in package.json.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
index.html Introduces a CSP meta tag intended to constrain resource loading and script execution.
src/components/MarkdownRenderer.tsx Removes hast-util-sanitize type import and relies on inferred typing for the sanitizer schema.
package.json Reorders/adds ESLint plugin devDependencies (no functional runtime impact).
.Jules/sentinel.md Documents the CSP change in the security log.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

index.html Outdated
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

The CSP shipped in index.html includes dev-only relaxations (script-src 'unsafe-inline' and connect-src ws:). Because index.html is used for production builds too, this weakens XSS mitigations in prod (inline script execution and unrestricted WebSocket connections). Consider splitting CSP by environment (dev vs prod) and tightening production by removing unsafe-inline and replacing ws: with an explicit localhost-only WebSocket allowlist (or omitting it entirely in prod).

Suggested change
content="default-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://cdn.jsdelivr.net https://pypi.org https://files.pythonhosted.org ws:; worker-src 'self' blob:; object-src 'none'; base-uri 'self'; form-action 'self';"
content="default-src 'self'; script-src 'self' 'unsafe-eval' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://cdn.jsdelivr.net https://pypi.org https://files.pythonhosted.org ws://localhost:* wss://localhost:*; worker-src 'self' blob:; object-src 'none'; base-uri 'self'; form-action 'self';"

Copilot uses AI. Check for mistakes.
Comment on lines 8 to 10
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://cdn.jsdelivr.net https://pypi.org https://files.pythonhosted.org ws:; worker-src 'self' blob:; object-src 'none'; base-uri 'self'; form-action 'self';"
/>
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

PR description says the CSP restricts resource loading to specific allowlisted sources, but img-src currently allows any https: image. That’s a much broader permission than the described “specific CDNs” approach and can allow data exfiltration via image requests if XSS occurs. If external images aren’t required, consider removing https: or narrowing to explicit domains.

Copilot uses AI. Check for mistakes.
Comment on lines 418 to 423
const remarkPlugins = [remarkGfm]

const lessonSanitizerSchema: Schema = {
const lessonSanitizerSchema = {
tagNames: [
'a',
'blockquote',
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

Removing the Schema type annotation avoids the extra type dependency, but it also drops compile-time validation for this sanitizer schema (easy to introduce typos like className vs class or invalid keys). You can keep type-safety without adding hast-util-sanitize by using a derived type, e.g. satisfies Parameters<typeof rehypeSanitize>[0] (or the exported options/schema type from rehype-sanitize if available).

Copilot uses AI. Check for mistakes.
@saint2706
Copy link
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Feb 14, 2026

@saint2706 I've opened a new pull request, #378, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 4 commits February 14, 2026 11:26
- Remove 'unsafe-inline' from script-src in production
- Restrict img-src from 'https:' to specific domain
- Remove 'ws:' from connect-src in production
- Add dev-mode CSP relaxations via Vite plugin for HMR
- Add RehypeSanitizeOptions type to lessonSanitizerSchema

Co-authored-by: saint2706 <45678566+saint2706@users.noreply.github.com>
- Target specific CSP meta tag to avoid modifying other tags
- Add detailed comments explaining the transformation
- Make regex more specific to prevent false matches

Co-authored-by: saint2706 <45678566+saint2706@users.noreply.github.com>
- Use /s flag to match across newlines
- Extract and transform CSP content properly
- Verified transformation works with actual HTML structure

Co-authored-by: saint2706 <45678566+saint2706@users.noreply.github.com>
Harden CSP for production, preserve dev ergonomics
@saint2706 saint2706 merged commit 8e78463 into main Feb 14, 2026
1 check passed
@saint2706 saint2706 deleted the sentinel-csp-10355632473291607304 branch February 14, 2026 11:38
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.

2 participants

Comments