carlos / platform Public

static-dir-slash: Astra round 1 P1, no loop with splat or placeholder rules

The guard only stood aside for a rule naming the path outright, so a forced
"/about/* /about 301!", "/:slug /:slug 301!" or host-specific splat still
looped: the site sent /about/ to /about, resolve skips a rule's redirect of
/about to itself, and the edge sent /about back to /about/. The edge now
also stands aside when the rules would redirect the slash form
(redirectRules.redirectsSlashForm, the existing resolve with exists=true).
Regression tests for all four shapes, following redirects to the page, and
a non-forced rule that never fires leaving the redirect in place. Docs and
census proposal updated.

Findings: docs/superpowers/reviews/CODEX-FINDINGS-static-dir-slash-R1.md
(1 P1 fixed here; census approved for serveTree and internal/edge in R1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev f7c84fdc6b9bdee7a4bf6c24d054dced53aebf93 parent a85c690
8 files changed, +103 −20
  • docs/site/cli.md +2 −2
  • docs/superpowers/notes/census-proposal-static-dir-slash.md +2 −2
  • docs/superpowers/reviews/CODEX-FINDINGS-static-dir-slash-R1.md +30 −0
  • internal/edge/redirects.go +13 −0
  • internal/edge/redirects_test.go +44 −8
  • internal/edge/static.go +8 −4
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv +3 −3

Intent

Human

<task-notification> <task-id>blc5su8v6</task-id> <tool-use-id>toolu_01Bzzt1a8CByAoJLjsBVFvcv</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ce90495f-c7a7-490e-9b84-a6251050e87f/tasks/blc5su8v6.output</output-file> <status>completed</status> <summary>Background command "/home/paulca/.cache/tmp/static-dir-slash/run-review.sh" completed (exit code 0)</summary> </task-notification>

diff --git a/docs/site/cli.md b/docs/site/cli.md
index 3c6b02558..64091d7e1 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -422,8 +422,8 @@ rules. The edge does not serve the `_redirects` file itself.
A folder requested without its trailing slash, such as `/blog/post`, is
redirected with a 301 to `/blog/post/`, where its `index.html` is served.
Each page then has one address, and relative links in the page resolve
-against its own folder. If a `_redirects` rule names that path, the rule
-decides instead.
+against its own folder. If the site's `_redirects` rules name that path, or
+redirect its slash form, the folder is served at the path as asked instead.
#### Two builds at once
diff --git a/docs/superpowers/notes/census-proposal-static-dir-slash.md b/docs/superpowers/notes/census-proposal-static-dir-slash.md
index fc357bd6d..cc5938b05 100644
--- a/docs/superpowers/notes/census-proposal-static-dir-slash.md
+++ b/docs/superpowers/notes/census-proposal-static-dir-slash.md
@@ -4,7 +4,7 @@ Ruling `census-ruling-static-dir-slash`. The independent reviewer approves or re
| unit | change | read sites | what changed |
|---|---|---|---|
-| `internal/edge/static.go` `staticSite.serveTree` | body | unchanged (2) | A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", or a _redirects rule names the path. It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the tree it already read. |
+| `internal/edge/static.go` `staticSite.serveTree` | body | unchanged (2) | A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", a _redirects rule names the path, or the rules would redirect its slash form (redirectsSlashForm, the existing in-memory resolve with exists=true). It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the rules it already parsed. |
Envelopes re-pinned: `internal/edge`.
@@ -14,6 +14,6 @@ Recorded dispositions, which each change must still satisfy:
- `internal/edge/static.go` `staticSite.serveTree`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added
-Seal: `1de834976c615fed28567ca0a9ae7526eaa35341e07898feb112f4e1b0ddee8d` → `2c784a68ded2871314eb7aaa1689342d94b944a4f19b91a31b35085e4190ed00`.
+Seal: `1de834976c615fed28567ca0a9ae7526eaa35341e07898feb112f4e1b0ddee8d` → `fb7cd756f7c3eb2dc019c8fd55fea5475e2df7ee3305fbc693ae669f257f374f`.
Overlay: `internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-static-dir-slash-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-static-dir-slash-R1.md
new file mode 100644
index 000000000..e28e2afdb
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-static-dir-slash-R1.md
@@ -0,0 +1,30 @@
+Reviewed `origin/main...cba536da6d3c0b25ddaf7d7c6e62aeb14cfbcabe`, round 1.
+
+**P1 — Redirect rules: splat and placeholder rules create a loop.**
+
+With `about/index.html` and `_redirects` containing `/about/* /about 301!`:
+
+- `/about/` redirects to `/about`.
+- `/about` skips the rule’s self-redirect, then the new branch redirects to `./about/`.
+- Following redirects never reaches the page.
+
+Verified with direct `serveTree` calls. The same failure occurs with `/:slug /:slug 301!` and a host-specific splat rule.
+
+Evidence: `internal/edge/static.go:539–555` uses `names` to suppress the automatic redirect, but `internal/edge/redirects.go:429–434` excludes splats and placeholders. The self-redirect skip is at `internal/edge/redirects.go:404–405`.
+
+Concrete fix: add a separate check for slash canonicalization that recognizes matching forced rules, including splats and placeholders, when their self-redirect is skipped. Keep the probe guard’s narrower `names` semantics unchanged. Add regression tests for these cases.
+
+Fault family: **automatic canonicalization must not introduce cycles with existing site redirects.**
+
+No P2 or P3 findings.
+
+The content-type test still checks that identical bytes with different representation types receive different validators. Cache admission excludes 301s; password and protection checks remain before the new response; analytics requires GET/200.
+
+Validation: direct handler checks passed. Existing HTTP tests were blocked by the sandbox refusing a loopback listener. No tracked files were edited; the temporary test file was removed.
+
+Census verdicts:
+
+- **Approve — `staticSite.serveTree`:** unchanged filesystem reads and containment; no added root authority or weakened protection check.
+- **Approve — `internal/edge` envelope:** the changed production function preserves its recorded read boundary. The redirect correctness defect above independently blocks merge.
+
+**NOT READY**
\ No newline at end of file
diff --git a/internal/edge/redirects.go b/internal/edge/redirects.go
index df918c316..51d5f9b51 100644
--- a/internal/edge/redirects.go
+++ b/internal/edge/redirects.go
@@ -439,6 +439,19 @@ rules:
return false
}
+// redirectsSlashForm reports whether the rules would answer the slash form
+// of rawPath (rawPath + "/", whose cleaned path is p) with a redirect, given
+// that the folder there exists. serveTree asks before sending a folder
+// requested without its slash to the slash form: when the site's own rules
+// redirect that form anywhere, the edge's redirect would at best add a hop
+// and at worst loop (a forced "/about/* /about 301!" answers /about/ with
+// /about, and resolve skips the rule's redirect of /about to itself), so the
+// edge leaves the path alone. A nil set redirects nothing.
+func (rs *redirectRules) redirectsSlashForm(host, p, rawPath, rawQuery string) bool {
+ act, ok := rs.resolve(host, p, rawPath+"/", rawQuery, true)
+ return ok && act.location != ""
+}
+
// hostOf is the host of a "scheme://host[:port]" prefix, normalized as
// requestHost normalizes a request's.
func hostOf(prefix string) string {
diff --git a/internal/edge/redirects_test.go b/internal/edge/redirects_test.go
index 8e026e106..bcf1414bc 100644
--- a/internal/edge/redirects_test.go
+++ b/internal/edge/redirects_test.go
@@ -361,16 +361,52 @@ func TestStaticDirectoryWithoutSlashRedirects(t *testing.T) {
}
}
-// A site whose _redirects names the directory has said what it wants there.
-// A forced rule sending /about/ to /about would otherwise loop with this
-// redirect, so the slash redirect stands aside and /about serves the page.
+// A site whose _redirects send the slash form back to the bare path would
+// loop with this redirect, whatever shape the rule takes: named outright, a
+// splat, a placeholder, or for this host only. The slash redirect stands
+// aside, and /about serves the page.
func TestStaticDirectorySlashRedirectYieldsToTheSitesRules(t *testing.T) {
- srv, c := redirectFixture(t, "/about/ /about 301!\n")
const host = "site.example.com"
- if got := fetch(t, c, "GET", srv.URL, host, "/about/"); got.code != 301 || got.location != "/about" {
- t.Fatalf("GET /about/ = %d %q, want the site's 301 to /about", got.code, got.location)
+ for _, rules := range []string{
+ "/about/ /about 301!\n",
+ "/about/* /about 301!\n",
+ "/:slug /:slug 301!\n",
+ "https://site.example.com/about/* https://site.example.com/about 301!\n",
+ } {
+ srv, c := redirectFixture(t, rules)
+ if got := fetch(t, c, "GET", srv.URL, host, "/about/"); got.code != 301 || !strings.HasSuffix(got.location, "/about") {
+ t.Errorf("rules %q: GET /about/ = %d %q, want the site's 301 to /about", rules, got.code, got.location)
+ }
+ if got := fetch(t, c, "GET", srv.URL, host, "/about"); got.code != 200 || got.body != "about" {
+ t.Errorf("rules %q: GET /about = %d %q %q, want 200 \"about\" (no slash redirect, no loop)", rules, got.code, got.location, got.body)
+ }
+ // Following redirects from either form ends on the page, never in a
+ // loop. (A rule with a host redirects to that host, which the test
+ // client cannot dial; the two answers above already show no loop.)
+ if strings.HasPrefix(rules, "https://") {
+ continue
+ }
+ for _, start := range []string{"/about", "/about/"} {
+ req, _ := http.NewRequest("GET", srv.URL+start, nil)
+ req.Host = host
+ resp, err := (&http.Client{}).Do(req)
+ if err != nil {
+ t.Errorf("rules %q: following %s: %v", rules, start, err)
+ continue
+ }
+ resp.Body.Close()
+ if resp.StatusCode != 200 {
+ t.Errorf("rules %q: following %s ended %d", rules, start, resp.StatusCode)
+ }
+ }
}
- if got := fetch(t, c, "GET", srv.URL, host, "/about"); got.code != 200 || got.body != "about" {
- t.Fatalf("GET /about = %d %q %q, want 200 \"about\" (no slash redirect, no loop)", got.code, got.location, got.body)
+}
+
+// A non-forced rule never fires on a folder that exists, so it does not stop
+// the slash redirect: only rules that would redirect the slash form do.
+func TestStaticDirectorySlashRedirectIgnoresRulesThatDoNotFire(t *testing.T) {
+ srv, c := redirectFixture(t, "/about/* /elsewhere 301\n")
+ if got := fetch(t, c, "GET", srv.URL, "site.example.com", "/about"); got.code != 301 || got.location != "./about/" {
+ t.Fatalf("GET /about = %d %q, want 301 ./about/", got.code, got.location)
}
}
diff --git a/internal/edge/static.go b/internal/edge/static.go
index 0a9a03ac5..78e276802 100644
--- a/internal/edge/static.go
+++ b/internal/edge/static.go
@@ -537,16 +537,20 @@ func (s *staticSite) serveTree(tree servedTree, w http.ResponseWriter, r *http.R
return
}
if !rewritten && isDir && r.URL.Path != "" && !strings.HasSuffix(r.URL.Path, "/") &&
- !tree.redirects.names(requestHost(r.Host), p) {
+ !tree.redirects.names(requestHost(r.Host), p) &&
+ !tree.redirects.redirectsSlashForm(requestHost(r.Host), p, r.URL.Path, r.URL.RawQuery) {
// A directory asked for without its trailing slash goes to the
// slash form, as GitHub Pages and Netlify send it: one URL per
// page, so analytics does not count /blog/post and /blog/post/
// as two, and the page's relative links resolve against its own
// directory rather than its parent. Relative, so it survives any
// prefix the request arrived under; "./" so a first segment with
- // a colon is never read as a scheme. A site whose _redirects
- // names this path has said what it wants here (a forced
- // "/about/ /about 301!" would otherwise loop), so it is left be.
+ // a colon is never read as a scheme. The site's _redirects come
+ // first: a rule naming this path says the site has a page here,
+ // and a rule that would redirect the slash form (a forced
+ // "/about/ /about 301!", "/about/* /about 301!" or
+ // "/:slug /:slug 301!") would loop with this one, so in either
+ // case the path is served as it is.
loc := "./" + path.Base(r.URL.EscapedPath()) + "/"
if q := r.URL.RawQuery; q != "" {
loc += "?" + q
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index a88c5d0bd..840b20d29 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -30,4 +30,4 @@ plan14-root-reads-rootfs-apps-3-workers.tsv 862d7383ad60d522d6b16f8a545c4cfa37de
plan14-root-reads-fresh-box-446.tsv 862d7383ad60d522d6b16f8a545c4cfa37de3d2cc1ba83fec1aff3825a0fe8ab
plan14-root-reads-rootfs-apps-4.tsv e085917e271ee26877974461133f393ccc5d63add91d7aad2afe10b30977914e
plan14-root-reads-regional-domains-447.tsv 1de834976c615fed28567ca0a9ae7526eaa35341e07898feb112f4e1b0ddee8d
-plan14-root-reads-static-dir-slash.tsv 2c784a68ded2871314eb7aaa1689342d94b944a4f19b91a31b35085e4190ed00
+plan14-root-reads-static-dir-slash.tsv fb7cd756f7c3eb2dc019c8fd55fea5475e2df7ee3305fbc693ae669f257f374f
diff --git a/internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv b/internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv
index 083b02733..76ff3775e 100644
--- a/internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv
+++ b/internal/provision/testdata/plan14-root-reads-static-dir-slash.tsv
@@ -1,5 +1,5 @@
# Census overlay static-dir-slash, written by census-propose (#369). census-ruling-static-dir-slash, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-static-dir-slash.md.
# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@legacy 1459647714751786c5eb8c06e71d1c1a48fad424e5d59fa1a17a37907ab80e8d internal/edge/static.go staticSite.serveTree legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added;rev3=census-ruling-static-dir-slash;basis=A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", or a _redirects rule names the path. It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the tree it already read. file:Stat@1081,file:Stat@967 a7a576fcdc24947cbb3af8cf9b63992b63ece193c017faf099ab4a222ee2773e
-internal/edge/static.go staticSite.serveTree legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added;rev3=census-ruling-static-dir-slash;basis=A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", or a _redirects rule names the path. It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the tree it already read. file:Stat@1081,file:Stat@967 a7a576fcdc24947cbb3af8cf9b63992b63ece193c017faf099ab4a222ee2773e
-@coverage internal/edge afd15ca8d48fd3c4b4555889b12f4743298ba26b26b8b2ae244fd9109b8c34fa
+@legacy 7d6539646102e6b5f2a6189e382630c5027dfb11790c15ab973ab27dfa9ed2c7 internal/edge/static.go staticSite.serveTree legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added;rev3=census-ruling-static-dir-slash;basis=A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", a _redirects rule names the path, or the rules would redirect its slash form (redirectsSlashForm, the existing in-memory resolve with exists=true). It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the rules it already parsed. file:Stat@1081,file:Stat@967 2b330b38cd0a14d890c43711fc8892e968fcbef00d6cfdd10c6e1dccf9df59cb
+internal/edge/static.go staticSite.serveTree legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=PROPOSED-static-redirects;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=the same index-aware Stat lookup inside the extracted tree, now run at most twice (the request path, then once for a _redirects rewrite destination cleaned rooted inside the same tree); the Open moves to serveFile; the _redirects file itself is never answered; no root decision;rev3=census-ruling-edge-protection-2;basis=consults the edge protection matcher (internal/edgeguard, pure and in-memory) on the request path (probe tier, only when no file and no _redirects rule names it) and on a rewrite target (hard tier, only when the file is there), and may answer the guard's 404 block page through guardDecide before a redirect or the rewritten file; the _redirects lookup gains an in-memory names check; the same index-aware Stat lookups inside the extracted tree, unchanged; no read added;rev3=census-ruling-static-dir-slash;basis=A directory requested without its trailing slash now answers a 301 to a relative "./<base>/" (query kept) instead of serving its index.html, unless the request was rewritten, the path ends in "/", a _redirects rule names the path, or the rules would redirect its slash form (redirectsSlashForm, the existing in-memory resolve with exists=true). It opens and stats exactly the files it did before; the new branch only writes a Location header and a status, from the request path and the rules it already parsed. file:Stat@1081,file:Stat@967 2b330b38cd0a14d890c43711fc8892e968fcbef00d6cfdd10c6e1dccf9df59cb
+@coverage internal/edge b11d75a49ff9d2ea83c3c5bd89ea3692997e3fcd9488fda09f6e72410fbb9d3d