| | |

GitHub Pages 05 🛡️ HTTPS & Security — Enforcing SSL, fixing mixed content, and verifying domains via TXT records

⏱️ Estimated read: 10 min | |

Securing a website is no longer an optional feature; it is a fundamental requirement for trust, search engine ranking, and browser compatibility. GitHub Pages provides automated HTTPS support, leveraging Let’s Encrypt to generate and renew SSL certificates for your hosted sites. While this automation handles the heavy lifting, site owners must ensure their configuration correctly enforces these standards and accounts for security risks such as mixed content or domain takeovers.

When you configure a custom domain, the security boundary shifts. You are no longer just relying on the safety of github.io; you are responsible for proving ownership of your domain to GitHub. This prevents “subdomain takeovers,” a vulnerability where a malicious actor could claim your domain if you were to delete your GitHub repository but forget to remove the DNS records pointing to GitHub’s infrastructure. Furthermore, as sites grow, managing asset paths to avoid “mixed content” errors becomes a critical maintenance task.

This chapter details how to enable and enforce HTTPS in your GitHub repository settings, the mechanics of using TXT records for domain verification, and the strategies for identifying and resolving mixed content warnings. We will cover the configuration steps necessary to ensure your site is secure by default and resilient against common security misconfigurations.

Key point: HTTPS is automatically provisioned for GitHub Pages, but you must manually enable “Enforce HTTPS” to secure your traffic; domain verification via TXT records is the critical defense mechanism that prevents malicious actors from hijacking your custom domain if your repository is deleted or renamed.


Why X exists

The HTTPS requirement problem. Modern web browsers actively penalize sites that do not use HTTPS, marking them as “Not Secure” and blocking certain features like geolocation or service workers. GitHub Pages exists to provide free, automated SSL, but because GitHub cannot control your DNS until you prove ownership, it requires an opt-in step to enforce the connection.

The “Mixed Content” problem. Even if your site is served over HTTPS, if your code attempts to load images, scripts, or stylesheets over an unencrypted HTTP connection, browsers will block those assets to protect the user. This “mixed content” behavior breaks site layout and functionality, necessitating a shift to relative paths or protocol-relative URLs.

The Domain Takeover problem. If a developer configures example.com to point to a GitHub repository, but then deletes the repository or renames the username, that DNS record still points to GitHub. If another user creates a repository with the same name, they could effectively “take over” the domain example.com and serve malicious content. Domain verification via TXT records exists to prove you own the domain, preventing this orphan scenario.

The Ownership Verification problem. When you set a DNS CNAME record, you are asserting that you own a domain. Because DNS is decentralized, GitHub needs an independent way to verify this assertion. TXT records provide a standardized way to store arbitrary text in the DNS system that GitHub can query, acting as a cryptographic handshake that verifies the user has the authority to host content on that domain.

The trade-off. The trade-off for these security features is the “Propagation Wait Time.” DNS changes and verification checks are not instantaneous. Security and verification protocols require time for records to propagate across the global DNS network, which creates a delay between configuration and active site security.


a. Enforcing HTTPS

Enforcing HTTPS is a repository-level setting. While GitHub Pages will attempt to provide an SSL certificate as soon as your domain is configured, you must enable the “Enforce HTTPS” toggle in your repository’s Pages settings. This configuration tells GitHub to reject any non-SSL (HTTP) requests and permanently redirect them to the secure (HTTPS) version of the site.

When you enable this, GitHub coordinates with certificate authorities to generate an SSL certificate. This process usually completes within a few minutes, but can take up to an hour depending on the complexity of your domain setup and certificate queue availability.

# Workflow to enforce HTTPS
1. Go to Settings > Pages
2. Locate 'Enforce HTTPS'
3. Check the box (If grayed out, DNS is not fully propagated)

If the checkbox is grayed out, it indicates that GitHub has not yet verified the DNS records (specifically the A or CNAME records). The system cannot secure a domain it does not yet recognize as pointing to its servers, so you must ensure your DNS is configured and propagated before attempting to enable this setting.

b. Mixed Content Resolution

Mixed content occurs when an HTTPS site tries to load resources over HTTP. This often happens because developers hardcode links as http://example.com/image.jpg or use absolute paths that do not dynamically switch based on the site’s protocol. Browsers treat these as security threats because an attacker could modify the unencrypted resource in transit.

The solution is to use relative paths for all internal assets. Instead of linking to http://yoursite.com/css/style.css, you should link to ./css/style.css. This ensures that if the site is loaded over HTTPS, the browser looks for the asset over HTTPS as well.

<!-- ❌ BAD: Hardcoded HTTP -->
<link rel="stylesheet" href="http://yoursite.com/css/main.css">

<!-- ✅ GOOD: Relative Path -->
<link rel="stylesheet" href="./css/main.css">

If you are using external APIs or CDNs, ensure that you always use the https:// prefix, or omit the protocol entirely (using //cdn.example.com/...), which tells the browser to inherit the protocol from the current page.

c. TXT Verification and Takeover Prevention

Domain verification is the process of adding a TXT record to your DNS settings. This record contains a unique token provided by GitHub. GitHub’s servers periodically scan the DNS records of your custom domain; if they find the token, they verify that you have administrative access to that domain’s DNS provider.

This is the primary defense against domain takeover. By requiring TXT verification, GitHub ensures that even if a repository is deleted, the CNAME record is useless unless the DNS verification TXT record is also present.

# Example TXT record format
Host: _github-pages-challenge-yourusername
Value: <unique-token-from-github-settings>

This ensures that only the person with the ability to modify the domain’s DNS zone can prove ownership. It creates a secondary layer of security that operates independently of the GitHub repository’s lifecycle.


Complete Example Session

# ============================================
# PART 1: THE TXT VERIFICATION
# ============================================
# GitHub Settings > Pages > Custom Domain > Verify
# GitHub gives you:
#   Host: _github-pages-challenge-yourusername
#   Value: 1234567890abcdef

# ============================================
# PART 2: DNS CONFIGURATION (SHOULD BE DONE)
# ============================================
# A Records for root domain
# CNAME for www subdomain

# ============================================
# PART 3: ENFORCING HTTPS
# ============================================
# Once DNS propagates, check Settings > Pages > Enforce HTTPS

# ============================================
# PART 4: RELATIVE PATHS (MIXED CONTENT FIX)
# ============================================
# index.html
# Change: <img src="http://cdn.com/img.png">
# To: <img src="https://cdn.com/img.png">

# ============================================
# PART 5: PROTOCOL-RELATIVE LINKS
# ============================================
# <script src="//cdn.jquery.com/jquery.js"></script>
# (Inherits protocol: if page is https, script loads as https)

# ============================================
# PART 6: SECURITY HEADERS (VIA GITHUB ACTIONS)
# ============================================
# (GitHub Pages serves default headers, but you can 
# add meta tags for CSP in HTML)
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

# ============================================
# PART 7: VERIFICATION STATUS
# ============================================
# GitHub shows "Verified" status in the Custom Domain
# settings after TXT records are detected

# ============================================
# PART 8: REMOVAL OF ORPHANED DOMAINS
# ============================================
# If you delete a repo, verify the DNS records 
# are removed from your registrar

# ============================================
# PART 9: TROUBLESHOOTING CERTIFICATE ISSUES
# ============================================
# If "Enforce HTTPS" remains disabled, wait 1 hour
# Then toggle domain off and back on in settings

# ============================================
# PART 10: AUTOMATIC RENEWAL
# ============================================
# No manual intervention needed; GitHub manages 
# the Let's Encrypt certificate lifecycle

The parts above covered the verification process via TXT records, the enforcement of HTTPS, and the remediation of mixed content issues.


Quick Reference

Security Configuration

SettingActionPurpose
Enforce HTTPSToggle OnForce SSL/TLS
TXT RecordAdd to DNSDomain Ownership
Relative PathsFix CodePrevent Mixed Content
CSP MetaAdd to HTMLUpgrade requests

Verification Records

Record TypeHostValue
TXT_github-pages-challengeProvided Token

Common Mixed Content Solutions

ScenarioFix
CSS/JS linkUse relative paths (./)
API callChange http to https
CDN AssetsUse // protocol-relative

Best Practices

✅ Do This:

# Enable Enforce HTTPS in Repository Settings            // ✅
# Use protocol-relative URLs (//cdn.com/file.js)        // ✅
# Add the TXT verification record immediately          // ✅
# Use relative paths for all local assets              // ✅
# Check the "Verify" status in Pages settings          // ✅

❌ Don’t Do This:

# Hardcode 'http://' in your image paths               // ❌
# Ignore the "Enforce HTTPS" toggle                    // ❌
# Delete a repository without updating DNS records     // ❌
# Use absolute URLs for internal site navigation       // ❌
# Panic if the SSL certificate takes time to issue     // ❌

Common Pitfalls

PitfallWhy It HappensFix
HTTPS Checkbox disabledDNS not propagatedWait 24-48 hours
Browser blocking imagesMixed Content (HTTP/HTTPS)Fix image paths to HTTPS/Relative
Domain hijacking riskOrphaned CNAME recordUse TXT verification
Certificate errorDNS record pointing to wrong IPUpdate A records
Verification failedIncorrect TXT HostCheck exact Host string in Settings

Real-World Examples

1. Security Compliance

A bank’s developer portal ensuring all assets are loaded via https to meet corporate requirements.

2. Domain Hijacking Defense

An organization using TXT verification to ensure their main domain cannot be taken over.

3. Mixed Content Patch

Fixing a broken legacy site by converting all http links to relative ./ paths.

4. Automated Renewals

Using GitHub’s native SSL renewal (no manual cert management).

5. CSP Implementation

Adding meta tags to a blog to force the browser to upgrade insecure requests.

6. CDN Integration

Loading fonts from a secure Google Fonts URL https://fonts.googleapis.com.

7. Developer Identity

Verifying myname.com to GitHub Pages to boost SEO and trust.

8. Staging vs Production

Ensuring HTTPS is active on both staging and production custom domains.

9. Legacy Site Cleanup

Removing DNS records for a defunct project to prevent takeover.

10. DNS Propagation Monitoring

Using dig to verify TXT record is visible before triggering verification.


Visual

The Mixed Content Block

┌──────────────────────────────────────────────┐
│  HTTPS SITE (Secure)                         │
│  │                                           │
│  └─► Requesting image.png (HTTP) ◄─── BLOCK  │
│                                              │
│  BROWSER:                                    │
│  "This page is trying to load unauthenticated│
│   resources over HTTP."                      │
└──────────────────────────────────────────────┘

The Domain Verification Chain

┌──────────────────────────────────────────────┐
│  GITHUB PAGES                                │
│  "Who owns example.com?"                     │
│        │                                     │
│        ▼                                     │
│  DNS PROVIDER (TXT Record)                   │
│  "_github-pages-challenge: <token>"          │
│        │                                     │
│        ▼                                     │
│  GITHUB VERIFIED: Domain is owned.           │
└──────────────────────────────────────────────┘

Enforce HTTPS Logic

┌──────────────────────────────────────────────┐
│  USER REQUEST (HTTP)                         │
│        │                                     │
│        ▼                                     │
│  GITHUB PAGES SERVER                         │
│  (Check: Enforce HTTPS == True?)             │
│        │                                     │
│        ▼                                     │
│  301 MOVED PERMANENTLY                       │
│  (Redirect to HTTPS)                         │
└──────────────────────────────────────────────┘

Summary

ItemValue
SSL ProviderLet’s Encrypt (Automated)
Enforce HTTPSToggle in Repository Settings
VerificationTXT Records
Mixed ContentHTTP assets on HTTPS site
Security StrategyRelative links + HTTPS enforcement
DNS DependencyRequired for SSL issuance

Key takeaways:

  • Enforce HTTPS is a manual toggle. While GitHub provides the certificate, you must actively enable the enforcement setting in your repository configuration.
  • TXT verification is your armor. It proves ownership and prevents domain takeover, which is a critical security step for custom domains.
  • Mixed content breaks sites. Loading non-secure assets on a secure page will trigger browser security warnings and block your resources.
  • Use relative paths. This is the best defense against mixed content, as it allows assets to adapt automatically to the protocol of the page.
  • DNS takes time. Security configurations involving SSL and domain verification rely on DNS propagation, which is rarely instantaneous.

Remember: Security on GitHub Pages is a combination of infrastructure (HTTPS) and configuration (verification). By enforcing HTTPS and setting up TXT domain verification, you create a robust, verifiable, and secure environment that protects both your site content and your domain reputation.

Was this helpful?


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!