Skip to content

Conversation

@shahar1
Copy link
Contributor

@shahar1 shahar1 commented Dec 27, 2025

Copilot Summary

This pull request introduces a significant security improvement to the sphinx_airflow_theme by adding a Content Security Policy (CSP) header to the layout.html template. The CSP restricts the sources for scripts, styles, fonts, images, and other resources, enhancing the protection against cross-site scripting (XSS) and related attacks.

Security enhancements:

  • Added a <meta http-equiv="Content-Security-Policy"> tag to layout.html to enforce strict resource loading policies, specifying allowed sources for scripts, styles, fonts, images, connections, and more. This helps prevent XSS and content injection vulnerabilities.

Copilot AI review requested due to automatic review settings December 27, 2025 10:46
@shahar1 shahar1 force-pushed the fix-content-security-policy branch from db9a904 to 8aa638d Compare December 27, 2025 10:46
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

This pull request adds a Content Security Policy (CSP) meta tag to the Sphinx Airflow theme's layout template to enhance web application security by controlling which sources can load content.

Key changes:

  • Added CSP meta tag with directives for default sources and fonts to restrict content loading origins

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

@shahar1 shahar1 force-pushed the fix-content-security-policy branch 2 times, most recently from a60a681 to 637900c Compare December 27, 2025 10:57
@shahar1 shahar1 requested a review from Copilot December 27, 2025 10:57
@shahar1 shahar1 force-pushed the fix-content-security-policy branch from 637900c to 19690c9 Compare December 27, 2025 10:58
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

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


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

Comment on lines 259 to +274
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval'
https://www.apachecon.com
https://www.communityovercode.org
https://*.apache.org
https://*.scarf.sh;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com data:;
img-src 'self' data: https://*.apache.org https://*.scarf.sh;
connect-src 'self' https://*.apache.org https://*.scarf.sh;
frame-ancestors 'none';
object-src 'none';
base-uri 'self';
form-action 'self';
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The viewport meta tag has been removed but this is essential for responsive design on mobile devices. The CSP meta tag should be added without removing the viewport meta tag. Add back the line:
<meta name="viewport" content="width=device-width, initial-scale=1">

Copilot uses AI. Check for mistakes.
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval'
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The use of 'unsafe-inline' and 'unsafe-eval' in the script-src directive significantly weakens the Content Security Policy, as they allow inline scripts and eval() usage which are common XSS attack vectors. Consider using nonces or hashes for inline scripts instead of 'unsafe-inline', and refactor code to eliminate the need for 'unsafe-eval'. If these are required for third-party dependencies or Sphinx functionality, document why they are necessary and consider if they can be scoped more narrowly.

Suggested change
script-src 'self' 'unsafe-inline' 'unsafe-eval'
script-src 'self'

Copilot uses AI. Check for mistakes.
https://www.communityovercode.org
https://*.apache.org
https://*.scarf.sh;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The use of 'unsafe-inline' in the style-src directive weakens the Content Security Policy by allowing inline styles, which can be exploited for certain attacks. Consider using nonces or hashes for inline styles, or moving styles to external stylesheets. If 'unsafe-inline' is required for Sphinx functionality or third-party dependencies, document the necessity.

Suggested change
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
style-src 'self' https://fonts.googleapis.com;

Copilot uses AI. Check for mistakes.
Comment on lines +260 to +275
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval'
https://www.apachecon.com
https://www.communityovercode.org
https://*.apache.org
https://*.scarf.sh;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com data:;
img-src 'self' data: https://*.apache.org https://*.scarf.sh;
connect-src 'self' https://*.apache.org https://*.scarf.sh;
frame-ancestors 'none';
object-src 'none';
base-uri 'self';
form-action 'self';
">
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The CSP meta tag has inconsistent indentation. The opening line uses 4 spaces, but the policy directives use 6 spaces. For better readability and consistency, align all directives with the same indentation level, or consider placing the entire CSP on a single line to avoid formatting issues.

Suggested change
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval'
https://www.apachecon.com
https://www.communityovercode.org
https://*.apache.org
https://*.scarf.sh;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com data:;
img-src 'self' data: https://*.apache.org https://*.scarf.sh;
connect-src 'self' https://*.apache.org https://*.scarf.sh;
frame-ancestors 'none';
object-src 'none';
base-uri 'self';
form-action 'self';
">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.apachecon.com https://www.communityovercode.org https://*.apache.org https://*.scarf.sh; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com data:; img-src 'self' data: https://*.apache.org https://*.scarf.sh; connect-src 'self' https://*.apache.org https://*.scarf.sh; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; form-action 'self';">

Copilot uses AI. Check for mistakes.
@potiuk
Copy link
Member

potiuk commented Dec 27, 2025

I think we do not need that (And should not have it). CSP is added automatically by ASF hosting.
We should not override the headers. See https://infra.apache.org/tools/csp.html , also #1255

@potiuk
Copy link
Member

potiuk commented Dec 27, 2025

This is what we have today - added by the ASF Apache server serving our pages:

Screenshot 2025-12-27 at 12 01 31

@potiuk
Copy link
Member

potiuk commented Dec 27, 2025

Don't believe in everything that Copilot says ;)

@shahar1
Copy link
Contributor Author

shahar1 commented Dec 27, 2025

I think we do not need that (And should not have it). CSP is added automatically by ASF hosting.
We should not override the headers. See https://infra.apache.org/tools/csp.html , also #1255

Interesting, wasn't aware of that - thanks!
My browser still complains though (some of the fonts aren't rendered properly)

@shahar1
Copy link
Contributor Author

shahar1 commented Dec 27, 2025

I think we do not need that (And should not have it). CSP is added automatically by ASF hosting.
We should not override the headers. See https://infra.apache.org/tools/csp.html , also #1255

Interesting, wasn't aware of that - thanks!
My browser still complains though (some of the fonts aren't rendered properly)

I think that it blocks Google originated fonts.
Should we ask for approval to add a header for that?

@potiuk
Copy link
Member

potiuk commented Dec 27, 2025

I think we do not need that (And should not have it). CSP is added automatically by ASF hosting.
We should not override the headers. See https://infra.apache.org/tools/csp.html , also #1255

Interesting, wasn't aware of that - thanks! My browser still complains though (some of the fonts aren't rendered properly)

We should then embed those fonts in our page. The problem is that if we need fonts to be downloaded from somewhere (say google) - in order to render the page - this is Privacy concern that we don't want to deal with. Similarly I embedded screenshots from youtube videos to be served from our page rather than from youtube.com -> user needs to explicitly click on those to be redirected to youtube page, but there is no privacy tracking when they just view our page.

@potiuk
Copy link
Member

potiuk commented Dec 27, 2025

That's precisely why CSP in the ASF is supposed to prevent :)

@potiuk
Copy link
Member

potiuk commented Dec 27, 2025

BTW. Which page generates those font issues? I thought I looked at all pages before and have not seen any remaining CSP issues ?

@shahar1
Copy link
Contributor Author

shahar1 commented Dec 27, 2025

BTW. Which page generates those font issues? I thought I looked at all pages before and have not seen any remaining CSP issues ?

One of my browser's extensions caused the main page to raise those errors 🤦‍♂️
Sorry for the misunderstanding, I'll make future checks using anonymous browsing.

@shahar1 shahar1 closed this Dec 27, 2025
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