Skip to content

Move CSP from HTML meta tag to Traefik header set by OPENC3_ALLOW_HTTP#2872

Merged
jmthomas merged 6 commits into
mainfrom
traefik_csp
Feb 26, 2026
Merged

Move CSP from HTML meta tag to Traefik header set by OPENC3_ALLOW_HTTP#2872
jmthomas merged 6 commits into
mainfrom
traefik_csp

Conversation

@jmthomas
Copy link
Copy Markdown
Member

Eliminates duplicate index-allow-http.html and traefik-allow-http.yaml files by moving CSP policy into Traefik headers middleware with a Go template conditional. Users can now uncomment OPENC3_ALLOW_HTTP=1 in .env to allow HTTP connections instead of swapping config files.

…LOW_HTTP env var

Eliminates duplicate index-allow-http.html and traefik-allow-http.yaml files
by moving CSP policy into Traefik headers middleware with a Go template
conditional. Users can now uncomment OPENC3_ALLOW_HTTP=1 in .env to allow
HTTP connections instead of swapping config files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.83%. Comparing base (6aac97e) to head (18640ed).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2872      +/-   ##
==========================================
- Coverage   78.84%   78.83%   -0.02%     
==========================================
  Files         667      667              
  Lines       54527    54527              
  Branches      728      728              
==========================================
- Hits        42990    42984       -6     
- Misses      11459    11465       +6     
  Partials       78       78              
Flag Coverage Δ
python 80.84% <ø> (-0.01%) ⬇️
ruby-api 80.24% <ø> (-0.05%) ⬇️
ruby-backend 82.14% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

contentSecurityPolicy:
headers:
contentSecurityPolicy: >-
{{ if env "OPENC3_ALLOW_HTTP" }}default-src 'self' blob: data: http: https:; script-src 'unsafe-inline' 'unsafe-eval' http: https: blob:; connect-src blob: http: https: wss: ws:; style-src 'unsafe-inline' http: https:; object-src 'none';{{ else }}default-src 'self' blob: data: https: http://localhost:* http://host.docker.internal:* http://*.local:*; script-src 'unsafe-inline' 'unsafe-eval' https: blob: http://localhost:* http://host.docker.internal:* http://*.local:*; connect-src blob: https: wss: http://localhost:* http://host.docker.internal:* http://*.local:* ws://localhost:* ws://host.docker.internal:* ws://*.local:*; style-src 'unsafe-inline' https: http://localhost:* http://host.docker.internal:* http://*.local:*; object-src 'none';{{ end }}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This also allows for easily updating these values in config instead of hard coded in the html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Syntax inconsistency {{- if vs {{ if, although i don't think there's any meaningful difference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So the rule is {{- at the beginning of an action removes all trailing whitespace (including newlines) from the immediately preceding text. I think this maybe does matter. I will test and change all to one style.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The {{- actually broke the template so I removed these from the other templates

contentSecurityPolicy:
headers:
contentSecurityPolicy: >-
{{ if env "OPENC3_ALLOW_HTTP" }}default-src 'self' blob: data: http: https:; script-src 'unsafe-inline' 'unsafe-eval' http: https: blob:; connect-src blob: http: https: wss: ws:; style-src 'unsafe-inline' http: https:; object-src 'none';{{ else }}default-src 'self' blob: data: https: http://localhost:* http://host.docker.internal:* http://*.local:*; script-src 'unsafe-inline' 'unsafe-eval' https: blob: http://localhost:* http://host.docker.internal:* http://*.local:*; connect-src blob: https: wss: http://localhost:* http://host.docker.internal:* http://*.local:* ws://localhost:* ws://host.docker.internal:* ws://*.local:*; style-src 'unsafe-inline' https: http://localhost:* http://host.docker.internal:* http://*.local:*; object-src 'none';{{ end }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Syntax inconsistency {{- if vs {{ if, although i don't think there's any meaningful difference.

Comment thread compose.yaml Outdated
@sonarqubecloud
Copy link
Copy Markdown

@jmthomas jmthomas merged commit eb773fc into main Feb 26, 2026
42 of 43 checks passed
@jmthomas jmthomas deleted the traefik_csp branch February 26, 2026 21:11
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.

3 participants