fix: forge browsing, verified crawlers, ban feedback loop, coverage metrics and slow-attacker policy (1.6.0)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 20:26:56 -03:00
1 parent 393a31cebe
commit 54b9ae65cd
23 files changed
+802 -100

No files matched your search

+39
View File
@@ -103,7 +103,46 @@ func refusedProbe(path string) bool {
return false
}
var forgeGitea = map[string]bool{"src": true, "raw": true, "blame": true, "commits": true, "commit": true, "media": true, "history": true}
var forgeRef = map[string]bool{"branch": true, "commit": true, "tag": true}
var forgeGeneric = map[string]bool{"blob": true, "tree": true, "raw": true, "blame": true, "commits": true}
// ForgeBrowse reports whether the (decoded, lowercase, query-less) path is a
// code forge page that shows repository content: Gitea/Forgejo
// /{owner}/{repo}/(src|raw|blame|commits|commit|media|history)/(branch|commit|tag)/<ref>/<file>,
// GitHub style /{owner}/{repo}/(blob|tree|raw|blame|commits)/<ref>/<file> and
// GitLab style /{group}/{project}/-/(blob|tree|raw|blame|commits)/<ref>/<file>.
// A file named ".env" inside a repository is content, not a probe of the host.
// It needs an owner and a repo that are not dot names, so "/.env", "/.git/config"
// or "/app/.env" are never forge paths. Traversal markers are checked before.
func ForgeBrowse(path string) bool {
if len(path) == 0 || path[0] != '/' {
return false
}
seg := strings.Split(path[1:], "/")
if len(seg) < 4 || seg[0] == "" || seg[1] == "" || seg[0][0] == '.' || seg[1][0] == '.' {
return false
}
for i := 2; i+3 < len(seg); i++ { // GitLab: /group/project/-/blob/<ref>/<file>
if seg[i] == "-" && forgeGeneric[seg[i+1]] && seg[i+2] != "" && seg[i+3] != "" {
return true
}
}
if seg[2] != "" && seg[3] != "" && len(seg) >= 5 && seg[4] != "" {
if forgeGitea[seg[2]] && forgeRef[seg[3]] {
return true // Gitea: /owner/repo/src/commit/<sha>/<file>
}
if forgeGeneric[seg[2]] {
return true // GitHub: /owner/repo/blob/<ref>/<file>
}
}
return false
}
func isScanner(path string, status int) bool {
if ForgeBrowse(path) {
return false
}
for _, m := range sensitive {
if segment(path, m) {
return true
+32
View File
@@ -0,0 +1,32 @@
package core
import "testing"
func TestForgeBrowseIsNotScanner(t *testing.T) {
for _, p := range []string{
"/ciberfauna/sabia/src/commit/0123abcd/.gitignore",
"/ciberfauna/sabia/raw/commit/0123abcd/.gitignore",
"/lucasrguerra/LambdaMail/src/commit/0123abcd/.env.example",
"/ciberfauna/guara/blame/commit/0123abcd/.gitignore",
"/ciberfauna/acaua/commits/commit/0123abcd/.gitignore",
"/ciberfauna/acaua/src/branch/main/.gitignore",
"/ciberfauna/acaua/src/tag/v1.0.0/.env.example",
"/org/repo/blob/main/.gitignore",
"/org/repo/tree/main/.github/workflows",
"/group/proj/-/blob/main/.env.example",
} {
c := Classify("GET", p, 200)
if c.Cat != OK {
t.Errorf("%s: %+v", p, c)
}
}
}
func TestForgeBrowseKeepsRealProbes(t *testing.T) {
for _, p := range []string{"/.env", "/.git/config", "/app/.env", "/.gitignore", "/app/.git/config", "/x/y/.env",
"/ciberfauna/sabia/src/commit/abc/../../../.env", "/.git/src/commit/abc/x", "/a/b/src/main/.env", "/wp-config.php"} {
if c := Classify("GET", p, 200); c.Cat == OK {
t.Errorf("%s must stay a probe: %+v", p, c)
}
}
}