-
Notifications
You must be signed in to change notification settings - Fork 53
feat: standalone embeddable thread view with opt-in frame origins #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e445c46
e1f3d24
35fa115
0f28673
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,25 +13,26 @@ import ( | |
| ) | ||
|
|
||
| type Config struct { | ||
| Addr string `json:"addr"` | ||
| Data string `json:"data"` | ||
| DB string `json:"db"` | ||
| Uploads string `json:"uploads"` | ||
| Environment string `json:"environment"` | ||
| MetricsEnabled bool `json:"metrics_enabled"` | ||
| PublicURL string `json:"public_url"` | ||
| PublicAPIURL string `json:"public_api_url"` | ||
| CookieNamespace string `json:"cookie_namespace"` | ||
| DevBootstrap bool `json:"dev_bootstrap"` | ||
| GitHubClientID string `json:"github_client_id"` | ||
| GitHubClientSecret string `json:"github_client_secret"` | ||
| GitHubAllowedOrg string `json:"github_allowed_org"` | ||
| GitHubModeratorOrg string `json:"github_moderator_org"` | ||
| PushoverAPIToken string `json:"pushover_api_token"` | ||
| R2AccountID string `json:"r2_account_id"` | ||
| R2AccessKeyID string `json:"r2_access_key_id"` | ||
| R2SecretAccessKey string `json:"r2_secret_access_key"` | ||
| R2Endpoint string `json:"r2_endpoint"` | ||
| Addr string `json:"addr"` | ||
| Data string `json:"data"` | ||
| DB string `json:"db"` | ||
| Uploads string `json:"uploads"` | ||
| Environment string `json:"environment"` | ||
| MetricsEnabled bool `json:"metrics_enabled"` | ||
| PublicURL string `json:"public_url"` | ||
| PublicAPIURL string `json:"public_api_url"` | ||
| EmbedFrameAncestors []string `json:"embed_frame_ancestors"` | ||
| CookieNamespace string `json:"cookie_namespace"` | ||
| DevBootstrap bool `json:"dev_bootstrap"` | ||
| GitHubClientID string `json:"github_client_id"` | ||
| GitHubClientSecret string `json:"github_client_secret"` | ||
| GitHubAllowedOrg string `json:"github_allowed_org"` | ||
| GitHubModeratorOrg string `json:"github_moderator_org"` | ||
| PushoverAPIToken string `json:"pushover_api_token"` | ||
| R2AccountID string `json:"r2_account_id"` | ||
| R2AccessKeyID string `json:"r2_access_key_id"` | ||
| R2SecretAccessKey string `json:"r2_secret_access_key"` | ||
| R2Endpoint string `json:"r2_endpoint"` | ||
| } | ||
|
|
||
| func Defaults() Config { | ||
|
|
@@ -83,6 +84,9 @@ func Load(path string) (Config, error) { | |
| if env := os.Getenv("CLICKCLACK_PUBLIC_API_URL"); env != "" { | ||
| cfg.PublicAPIURL = env | ||
| } | ||
| if env := os.Getenv("CLICKCLACK_EMBED_FRAME_ANCESTORS"); env != "" { | ||
| cfg.EmbedFrameAncestors = ParseEmbedFrameAncestors(env) | ||
| } | ||
| if env := os.Getenv("CLICKCLACK_COOKIE_NAMESPACE"); env != "" { | ||
| cfg.CookieNamespace = env | ||
| } | ||
|
|
@@ -145,6 +149,10 @@ func (c *Config) ValidateServe() error { | |
| if publicAPIURL == "" { | ||
| publicAPIURL = publicURL | ||
| } | ||
| embedFrameAncestors, err := normalizeEmbedFrameAncestors(c.EmbedFrameAncestors) | ||
| if err != nil { | ||
| return fmt.Errorf("CLICKCLACK_EMBED_FRAME_ANCESTORS: %w", err) | ||
| } | ||
| if err := validatePublicURLPair(publicURL, publicAPIURL); err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -167,6 +175,7 @@ func (c *Config) ValidateServe() error { | |
| return fmt.Errorf("cookie policy: %w", err) | ||
| } | ||
| c.PublicAPIURL = publicAPIURL | ||
| c.EmbedFrameAncestors = embedFrameAncestors | ||
| c.CookieNamespace = namespace | ||
| c.PublicURL = publicURL | ||
| c.GitHubClientID = clientID | ||
|
|
@@ -176,6 +185,39 @@ func (c *Config) ValidateServe() error { | |
| return nil | ||
| } | ||
|
|
||
| // ParseEmbedFrameAncestors parses the comma- or whitespace-separated format | ||
| // accepted by CLICKCLACK_EMBED_FRAME_ANCESTORS and --embed-frame-ancestors. | ||
| func ParseEmbedFrameAncestors(value string) []string { | ||
| return strings.FieldsFunc(value, func(r rune) bool { | ||
| return r == ',' || r == ' ' || r == '\t' || r == '\n' || r == '\r' | ||
| }) | ||
| } | ||
|
|
||
| func normalizeEmbedFrameAncestors(values []string) ([]string, error) { | ||
| seen := make(map[string]struct{}, len(values)) | ||
| normalized := make([]string, 0, len(values)) | ||
| for _, value := range values { | ||
| value = strings.TrimSpace(value) | ||
| if value == "" { | ||
| continue | ||
| } | ||
| parsed, err := url.Parse(value) | ||
| if err != nil || parsed.Opaque != "" || parsed.User != nil || parsed.Hostname() == "" || | ||
| strings.Contains(parsed.Hostname(), "*") || | ||
| (parsed.Scheme != "http" && parsed.Scheme != "https") || | ||
| (parsed.Path != "" && parsed.Path != "/") || parsed.RawQuery != "" || parsed.Fragment != "" { | ||
|
Comment on lines
+204
to
+208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Reject malformed port forms while validating configured origins. Go's Useful? React with 👍 / 👎. |
||
| return nil, fmt.Errorf("%q must be an HTTP(S) origin without a path, query, or fragment", value) | ||
| } | ||
| origin := (&url.URL{Scheme: strings.ToLower(parsed.Scheme), Host: strings.ToLower(parsed.Host)}).String() | ||
| if _, ok := seen[origin]; ok { | ||
| continue | ||
| } | ||
| seen[origin] = struct{}{} | ||
| normalized = append(normalized, origin) | ||
| } | ||
| return normalized, nil | ||
| } | ||
|
|
||
| func validatePublicURLPair(publicURL, publicAPIURL string) error { | ||
| if publicURL == "" || publicAPIURL == "" { | ||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When ClickClack is deployed through the checked Cloudflare pipeline, this environment setting never reaches the API process:
infra/cloudflare/worker.tsexplicitly constructsClickClackContainer.envVarsbut does not forwardenv.CLICKCLACK_EMBED_FRAME_ANCESTORS. Consequently, configuring the documented Worker variable leavescfg.EmbedFrameAncestorsempty and every embedded page remains restricted to'self', making cross-origin embedding unusable on that deployment.Useful? React with 👍 / 👎.