Skip to content

Add Cloudflare Worker to inject missing HTTP security headers - #271

Draft
lpmi-13 with Copilot wants to merge 2 commits into
mainfrom
copilot/investigate-fix-security-headers
Draft

Add Cloudflare Worker to inject missing HTTP security headers#271
lpmi-13 with Copilot wants to merge 2 commits into
mainfrom
copilot/investigate-fix-security-headers

Conversation

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

securityheaders.com rates the site F — all six security headers absent. GitHub Pages can't set HTTP response headers; the existing CSP/Referrer-Policy <meta> tags are browser-only and invisible to scanners.

Since the site is already Cloudflare-proxied (172.67.219.232), a Worker is the right insertion point.

Changes

  • cloudflare/worker.js — Worker that passes requests to origin and sets all six headers on every response:

    Header Value
    Strict-Transport-Security max-age=31536000; includeSubDomains; preload
    Content-Security-Policy matches existing meta tag policy
    X-Frame-Options SAMEORIGIN
    X-Content-Type-Options nosniff
    Referrer-Policy strict-origin-when-cross-origin
    Permissions-Policy camera/mic/geo/payment/usb disabled
  • cloudflare/wrangler.toml — routes worker over remotehack.space/*

  • .github/workflows/deploy-worker.yml — deploys on push to main when cloudflare/** changes; requires two repo secrets:

    • CLOUDFLARE_API_TOKEN (Edit Workers permission)
    • CLOUDFLARE_ACCOUNT_ID
  • _layouts/default.html — removes expired Chrome Prompt API origin-trial token (expired 24 Mar 2026)

Copilot AI added 2 commits August 2, 2026 17:46
The site is hosted on GitHub Pages behind Cloudflare. GitHub Pages cannot
set custom HTTP response headers, so securityheaders.com gave the site an F.

This adds a Cloudflare Worker (cloudflare/worker.js) that attaches the six
missing security headers to every response:

  - Strict-Transport-Security (HSTS, 1-year + preload)
  - Content-Security-Policy  (mirrors the existing HTML meta tag)
  - X-Frame-Options           (SAMEORIGIN)
  - X-Content-Type-Options    (nosniff)
  - Referrer-Policy           (strict-origin-when-cross-origin)
  - Permissions-Policy        (camera/mic/geo/payment/usb disabled)

A GitHub Actions workflow (.github/workflows/deploy-worker.yml) deploys the
worker automatically on every push to main that touches the cloudflare/
directory.  Two repository secrets must be added to activate it:
  CLOUDFLARE_API_TOKEN  — a token with "Edit Workers" permission
  CLOUDFLARE_ACCOUNT_ID — the Cloudflare account ID

Also removes the expired Chrome Prompt API origin-trial meta tag
(it expired 24 Mar 2026) from _layouts/default.html.
Copilot AI changed the title feat: add Cloudflare Worker to inject missing HTTP security headers Add Cloudflare Worker to inject missing HTTP security headers Aug 2, 2026
Copilot AI requested a review from lpmi-13 August 2, 2026 17:49
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