Skip to content

fix(config): reject site names that cannot be hostnames - #208

Open
xiaozou-second wants to merge 3 commits into
flock-php:mainfrom
xiaozou-second:fix/site-name-validation
Open

xiaozou-second wants to merge 3 commits into
flock-php:mainfrom
xiaozou-second:fix/site-name-validation

Conversation

@xiaozou-second

@xiaozou-second xiaozou-second commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #207

What and why

A site's name is its hostname: <name>.<tld>. flock link derived that name from the folder name, so a folder whose name cannot become a hostname (我的项目, Проект, a name made only of punctuation, or a name longer than 63 characters) was stored as a site with an empty name. Config.Domain then produced the domain .test, which the Caddy adapter rejects with subject does not qualify for certificate: '.test'. While the daemon was already running this was only a flock status warning; on the next daemon start the web server did not start, so every site was unreachable. The Add Site endpoint that the apps call passes config.SiteName to the same Config.Upsert, so it could store the same broken name.

This change validates site names as DNS labels with the same hostLabel rule UpsertProxy already uses:

  • internal/config/config.go: new ValidSiteName; Config.Upsert returns an error instead of storing an unusable name; Config.AllSites skips a parked subfolder whose name makes no site name.
  • internal/cli/sites.go: flock link reports that the folder name cannot become a site name and asks for one (flock link <name>) instead of storing an empty one.
  • internal/api/configapi.go: Add Site validates the derived or explicit name and answers with the folder and the same remedy, instead of the internal Upsert message that names an empty string. The Upsert guard stays as the last line of defence.
  • docs/sites.md: one sentence on naming a folder that the default does not fit.

The site-name errors state the whole rule (1-63 characters of a-z, 0-9 and inner hyphens), because hostLabel also enforces the length: a 64-character name made of allowed characters is rejected for its length.

A folder name that can be made into a hostname still is (My_App → my-app), and flock link my-project is unchanged. For a config that is already broken by an older version, cd <folder> && flock unlink removes the nameless entry; then flock link <name> links the folder properly.

How I tested it

  • Reproduced the bug end to end on Linux with a source build of main at 346231b: a daemon with a working okapp.test (HTTP 404 from its web server); flock link inside 我的项目 exited 0 and stored an empty site; flock status warned about .test; after a daemon restart nothing listened on the web port (HTTP 000). flock unlink plus a restart brought okapp.test back (HTTP 404).
  • The new tests fail on 346231b and pass with this change:
    • go test ./internal/config -run 'TestUpsertRejectsUnusableSiteNames|TestAllSitesSkipsParkedFoldersWithoutASiteName'
    • go test ./internal/cli -run 'TestLinkNeedsANameWhenTheFolderMakesNoSiteName|TestLinkRejectsNamesThatAreNotHostnames|TestLinkStoresValidSiteNames'
    • go test ./internal/api -run TestSiteAndParkedEndpoints (on 346231b Add Site returns 200 and stores the empty name)
  • go build ./..., go vet on every non-tool package, go test -race ./... (all packages) and go run ./tools/docslint pass on Linux; GOOS=windows and GOOS=darwin vet pass for the changed packages.
  • After the change: flock link inside 我的项目 exits non-zero, explains the folder name cannot become a site name and stores nothing; flock link my-project links it and okapp.test still answers after a daemon restart; parking a parent folder that contains 我的项目 lists only the usable subfolders; POST /v1/sites for that folder returns HTTP 400 "我的项目" can't be made into a site name — pass one: flock link <name> and stores nothing.
  • An already-broken config from 1.1.1 ({"name":"","path":"…/我的项目"}) recovers with flock unlink in the folder (unlinked ) followed by flock link my-project; verified with binaries built from 346231b and from this branch.

Only Linux was available locally; the change is Go-only and CI covers macOS, Windows, Linux amd64 and Linux arm64.

Checklist

  • I tested this change
  • I updated the docs in docs/, or no docs change is needed
  • New or changed texts follow lang/README.md (a new key when the meaning changes), or there are none
  • This changes only the daemon or CLI, not the apps
  • This changes the apps, and I made and tested the change on every platform:
    • macOS
    • Windows
    • Linux

Summary by CodeRabbit

  • Bug Fixes
    • Site names are checked against hostname requirements when linking a project or saving a site: 1–63 characters, using lowercase letters, digits, and interior hyphens. Invalid names are rejected with guidance to provide a valid name.
    • Parked folders that cannot produce valid site names are skipped when listing sites.
  • Documentation
    • Clarified when to provide a site name while linking a project, including when the folder name cannot be used as a hostname.

A folder whose name makes no hostname (a non-Latin name such as 我的项目, a
name made only of punctuation, or one longer than 63 characters) was linked
with an empty site name. Config.Domain then produced the domain ".test", and
the Caddy adapter rejects it ("subject does not qualify for certificate"), so
the next daemon start never brought the web server up and every site became
unreachable; while the daemon was running it was only a status warning.

Validate site names as DNS labels with the same hostLabel rule UpsertProxy
already uses:

- Config.Upsert returns an error instead of storing an unusable name, so the
  Add Site endpoint cannot store one either;
- flock link reports that the folder name cannot become a site name and asks
  for one (flock link <name>);
- Config.AllSites skips a parked subfolder whose name makes no site name.

flock link my-project keeps working, and a folder name that can be made into
a hostname (My_App) still becomes one (my-app). docs/sites.md says how to name
a folder the default does not fit.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Site names are validated before the link command, API, and Config.Upsert store them. Invalid derived names produce an error that directs the caller to provide a name. AllSites skips parked folders with invalid derived names.

Changes: Site name validation

Layer / File(s) Summary
Validate linked and stored site names
internal/config/config.go, internal/cli/sites.go, internal/api/configapi.go, internal/config/config_test.go, internal/cli/sites_test.go, internal/api/api_test.go, docs/sites.md
ValidSiteName checks names against hostLabel. Upsert, flock link, and the site API reject invalid names. Tests cover rejected and accepted names, storage, and command and API responses. The documentation explains when to provide a name.
Skip parked folders with invalid names
internal/config/config.go, internal/config/config_test.go
AllSites skips parked folders whose derived names are invalid. Tests cover valid and invalid derived names.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested reviewers: lukas-frey

Merge Risk: Minimal · up to e7940

This change rejects site names that cannot be DNS labels and gives callers a clear remedy, which prevents unusable entries such as .test. No merge-blocking risk is identified.

Security architecture risk: Low · up to e7940

The change prevents newly linked sites from storing names that can stop all local sites from loading. The remaining risk is limited to existing sites with invalid names: some edits are blocked until the site is relinked, and a failed pin request can still change a project file.

Retained concerns

  • Low · security · observed: Previously linked records whose names fail the new rule are still discoverable, but the shared Upsert gate now rejects in-place updates, including HTTPS settings and extra-domain removal. Operators can still unlink and relink with a valid name, but that is a site-wide recovery action rather than a targeted settings change.
  • Low · reliability · observed: For an API-addressable legacy site with a now-invalid name, pinning a runtime version or document root can write the project file before the new validation rejects the update that would clear the corresponding site override. The API returns an error and leaves the persisted override in place, but the project file is already changed. Retrying without repairing the name does not complete the transition.
Security review details

Security Blast Radius

  • inferred — The affected availability boundary is the local daemon's shared site-serving configuration: the reported startup failure from one empty hostname could affect every site on that daemon. The PR narrows the inputs that can create that state and does not add a remote entrypoint.

Trust Boundaries and Controls

  • observed — The existing local API accepts a caller-supplied name or derives one from an existing directory. It now validates the normalized value before passing it to persistence. That check constrains the hostname input; it does not grant authority or replace the transport's existing access controls.

Hardening Proposals

  • proposed — For a pin operation that would clear a stored override, check whether that update can pass the site-name rule before writing the project file. Keep unlink available as the recovery path for invalid legacy names.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(config): reject site names that cannot be hostnames" matches the main change: Upsert and AllSites now reject site names that cannot be DNS labels, and flock link and the Add Site endpoi…
Linked Issues check Passed Issue #207 requires three things: flock link rejects a folder-derived name that cannot be a hostname, tells the user to pass flock link <name>, and stores nothing; site names follow the DNS-label …
Out of Scope Changes check Passed Each changed area maps to #207 or to direct support for it. internal/config/config.go adds ValidSiteName and changes Upsert and AllSites, which are the storage and parked-folder objectives. `i…
Description check Passed The description follows the repository template. It links issue #207 with "Fixes #207", and it has the "What and why" and "How I tested it" sections with detailed content. It also includes the checkli…
Full details: Title check

Explanation

The title "fix(config): reject site names that cannot be hostnames" matches the main change: Upsert and AllSites now reject site names that cannot be DNS labels, and flock link and the Add Site endpoint are updated to match. It is specific, concise, and follows a conventional-commit style.

Full details: Linked Issues check

Explanation

Issue #207 requires three things: flock link rejects a folder-derived name that cannot be a hostname, tells the user to pass flock link &lt;name&gt;, and stores nothing; site names follow the DNS-label rule; and flock park does not list nameless subfolders. The reviewed head (e7940ec) shows the following. internal/config/config.go Config.Upsert returns an error when !ValidSiteName(site.Name), and its message states the 1-63 character rule. This guards the storage path, so no nameless site can be stored. Config.AllSites skips a parked folder when !ValidSiteName(SiteName(e.Name())), which covers the flock park input path. internal/api/configapi.go POST /v1/sites derives the name when body.Name is empty. When the derived name is invalid, it returns an error that names the folder and gives flock link &lt;name&gt;. An explicit invalid name gets a 1-63 character message. Both paths return before Upsert, so the Add Site endpoint stores nothing unusable. The explicit-name path still normalizes with config.SiteName, so a valid name such as My_App keeps the existing behavior. Limits: the body of ValidSiteName and the new test files were truncated or not read. The exact length and hyphen rules rest on the error text and the PR description. The flock link CLI path (internal/cli/sites.go) was not re-read at this head; the earlier review found it correct, and the change summary is consistent with it. Diff tools were unavailable for this head, so the review used whole-file reads only.

Full details: Out of Scope Changes check

Explanation

Each changed area maps to #207 or to direct support for it. internal/config/config.go adds ValidSiteName and changes Upsert and AllSites, which are the storage and parked-folder objectives. internal/api/configapi.go changes POST /v1/sites to give the remedy for an unnameable folder and to validate explicit names. The PR description and linked issue name the Add Site endpoint as an affected path, so this change falls within scope. internal/cli/sites.go and the related tests cover the flock link objective. docs/sites.md adds one sentence supporting the new flock link &lt;name&gt; guidance. The apps, unrelated commands, and the normal valid-name path (my-project, My_App to my-app) were not shown to change. No unrelated change was found in the inspected evidence. Limits: the internal/cli/sites.go and test-file bodies were not re-read at this head, so their contents rely on the change summary.

Full details: Description check

Explanation

The description follows the repository template. It links issue #207 with "Fixes #207", and it has the "What and why" and "How I tested it" sections with detailed content. It also includes the checklist. The problem, the fix in each affected file, the Add Site behavior, and the recovery path are all explained. The docs and testing items are checked. The app-platform items are left unchecked, which is correct because the change touches only the daemon and CLI. The description is complete and specific.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: flock-php/flock
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 346231b
  • Layers: Repository YAML (base), Repository UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05ad9db7-8163-49c6-8c57-962e3a4bf867
Commits

Reviewing files that changed from the base of the PR and between 8aa7d0f and e7940ec.

Files selected for processing: 6

  • internal/api/api_test.go
  • internal/api/configapi.go
  • internal/cli/sites.go
  • internal/cli/sites_test.go
  • internal/config/config.go
  • internal/config/config_test.go
Files skipped from review as they are similar to previous changes: 2

  • internal/cli/sites.go
  • internal/config/config.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@github-actions

Copy link
Copy Markdown

This pull request claims issue #207.

ValidSiteName enforces the 1-63 character DNS-label limit through hostLabel,
but the rejection messages only named the allowed characters. A 64-character
name made of a-z, 0-9 and hyphens was rejected with a sentence that described
exactly that name as allowed. State the whole rule, and assert the length
limit in the tests.
The Add Site endpoint the apps call passes the picked folder's name to
Config.Upsert. That guard now rejects a name that cannot be a hostname, but
the handler returned the internal message ("\"\" is not a valid site name ...),
which is the only feedback the apps show and names an empty string instead of
the folder. Validate the derived or explicit name in the handler and answer
with the folder and the CLI remedy; the Upsert guard stays as the last line of
defence.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claimed A pull request has claimed this issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flock link stores a nameless site when the folder name cannot be a hostname, and the web server then fails to start

1 participant