Skip to content

feat: support wildcard subdomain matching in trusted_domains - #1121

Open
dono-zz wants to merge 4 commits into
ArtalkJS:masterfrom
dono-zz:feat/wildcard-trusted-domains
Open

feat: support wildcard subdomain matching in trusted_domains#1121
dono-zz wants to merge 4 commits into
ArtalkJS:masterfrom
dono-zz:feat/wildcard-trusted-domains

Conversation

@dono-zz

@dono-zz dono-zz commented Apr 6, 2026

Copy link
Copy Markdown

Summary

  • Add wildcard pattern support (e.g. https://*.example.com) for trusted_domains config and site URLs
  • The wildcard * matches exactly one subdomain level — *.example.com matches sub.example.com but not example.com or a.b.example.com
  • Scheme must match (https://*.example.com won't match http://sub.example.com)
  • Fully backward compatible — exact domain matching is preserved, no config changes needed for existing setups

Motivation

When domains are frequently blocked (e.g. by regional firewalls), operators need to quickly spin up new subdomains. Currently every new subdomain must be manually added to trusted_domains or site URLs. With wildcard support, https://*.example.com covers all future subdomains automatically.

Changes

  • server/middleware/cors.go: Modified CheckOriginTrusted() to check wildcard patterns alongside exact matches. Added matchWildcardOrigin() helper function.
  • server/middleware/cors_test.go: Added 15 test cases covering matching, non-matching, edge cases, and scheme validation.

Usage

trusted_domains:
  - https://*.example.com    # matches any single-level subdomain
  - https://exact.other.com  # exact match still works

Or via site URLs in the Dashboard — add https://*.example.com as a site URL.

Test plan

  • Unit tests pass (go test ./server/middleware/ -run TestMatchWildcard)
  • Tested against production Artalk v2.9.1 with live data (read-only volume mount)
  • Verified wildcard CORS headers returned correctly for matching subdomains
  • Verified non-matching origins (bare domain, nested subdomain, different scheme, unrelated domain) are correctly rejected
  • Verified existing exact-match domains continue to work

Idea and used by https://lk21.mobile

Add wildcard pattern support (e.g. `https://*.example.com`) for
trusted_domains config and site URLs. This allows dynamically trusting
all subdomains under a base domain without listing each one explicitly.

The wildcard `*` matches exactly one subdomain level — `*.example.com`
matches `sub.example.com` but not `example.com` or `a.b.example.com`.
Scheme must also match. Exact domain matching is fully preserved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
do124574 and others added 3 commits April 6, 2026 08:19
Add rel="ugc" alongside nofollow, noreferrer, noopener on all
user-generated links (avatar, nick, markdown content). This follows
Google's 2019 recommendation for qualifying UGC outbound links.

Reference: ArtalkJS#1120

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants