Repository navigation
fix(security): add Content-Security-Policy header to web gateway - #966
Conversation
The web gateway set X-Frame-Options and X-Content-Type-Options but had no Content-Security-Policy header. Without CSP, there is no browser- enforced mitigation against XSS attacks. This adds a tailored CSP that matches the resources the frontend actually loads. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove cdnjs.cloudflare.com from script-src (not used in codebase) - Add explicit object-src 'none' per security best practice - Add regression test asserting CSP header presence and directives Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the security posture of the web gateway by introducing a Content-Security-Policy header. This measure helps protect users from malicious content injection and ensures that only trusted sources are allowed to execute scripts or load resources, building upon previous security efforts and incorporating necessary adjustments for external dependencies. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a great security enhancement, adding a Content-Security-Policy header to the web gateway. The implementation is solid and includes a valuable test case to ensure the header is present and correct. My primary feedback is a suggestion to further harden the CSP by removing 'unsafe-inline' from the style-src directive, which would provide stronger protection against XSS attacks.
| header::HeaderValue::from_static( | ||
| "default-src 'self'; \ | ||
| script-src 'self' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com; \ | ||
| style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; \ |
There was a problem hiding this comment.
The style-src directive includes 'unsafe-inline', which allows the use of inline <style> blocks and style attributes. This is a potential security risk as it can be a vector for Cross-Site Scripting (XSS) if an attacker finds a way to inject content into the page.
This is likely needed due to style="display: none;" attributes in src/channels/web/static/index.html. To improve security, I recommend refactoring the frontend code to use a CSS class for controlling visibility instead of inline styles. For example:
CSS:
.hidden {
display: none;
}JavaScript:
// To hide
element.classList.add('hidden');
// To show
element.classList.remove('hidden');This change would allow you to remove 'unsafe-inline' from the CSP, making it more robust.
| style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; \ | |
| style-src 'self' https://fonts.googleapis.com; \ |
…rai#966) * fix(security): add Content-Security-Policy header to web gateway The web gateway set X-Frame-Options and X-Content-Type-Options but had no Content-Security-Policy header. Without CSP, there is no browser- enforced mitigation against XSS attacks. This adds a tailored CSP that matches the resources the frontend actually loads. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(security): address CSP review feedback - Remove cdnjs.cloudflare.com from script-src (not used in codebase) - Add explicit object-src 'none' per security best practice - Add regression test asserting CSP header presence and directives Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Gabe Hamilton <gabe@near.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…rai#966) * fix(security): add Content-Security-Policy header to web gateway The web gateway set X-Frame-Options and X-Content-Type-Options but had no Content-Security-Policy header. Without CSP, there is no browser- enforced mitigation against XSS attacks. This adds a tailored CSP that matches the resources the frontend actually loads. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(security): address CSP review feedback - Remove cdnjs.cloudflare.com from script-src (not used in codebase) - Add explicit object-src 'none' per security best practice - Add regression test asserting CSP header presence and directives Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Gabe Hamilton <gabe@near.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Supersedes #514.
Why this replacement exists:
difflabai/ironclawstagingAdditional adjustment included after #510:
script-srcnow allows bothhttps://cdn.jsdelivr.netandhttps://cdnjs.cloudflare.comPlease review/merge this replacement instead of the original blocked PR.