mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-04-08 17:48:44 +00:00
Compare commits
3 Commits
fix/nilpoi
...
fix/upgrad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7882bdd656 | ||
|
|
d8c2ef9801 | ||
|
|
71bb9803ac |
@@ -1,12 +1,12 @@
|
|||||||
services:
|
services:
|
||||||
playwright:
|
playwright:
|
||||||
image: mcr.microsoft.com/playwright:v1.52.0-noble
|
image: mcr.microsoft.com/playwright:v1.56.0-noble
|
||||||
init: true
|
init: true
|
||||||
network_mode: service:workspace
|
network_mode: service:workspace
|
||||||
command:
|
command:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- npx -y playwright@1.52.0 run-server --port 9001 --host 0.0.0.0
|
- npx -y playwright@1.56.0 run-server --port 9001 --host 0.0.0.0
|
||||||
|
|
||||||
valkey:
|
valkey:
|
||||||
image: valkey/valkey:8
|
image: valkey/valkey:8
|
||||||
|
|||||||
6
.github/workflows/go.yml
vendored
6
.github/workflows/go.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.cache/ms-playwright
|
~/.cache/ms-playwright
|
||||||
key: ${{ runner.os }}-playwright-${{ hashFiles('**/go.sum') }}
|
key: ${{ runner.os }}-playwright-1.56.0
|
||||||
|
|
||||||
- name: install node deps
|
- name: install node deps
|
||||||
run: |
|
run: |
|
||||||
@@ -46,8 +46,8 @@ jobs:
|
|||||||
|
|
||||||
- name: install playwright browsers
|
- name: install playwright browsers
|
||||||
run: |
|
run: |
|
||||||
npx --no-install playwright@1.52.0 install --with-deps
|
npx playwright@1.56.0 install --with-deps
|
||||||
npx --no-install playwright@1.52.0 run-server --port 9001 &
|
npx playwright@1.56.0 run-server --port 9001 &
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ var (
|
|||||||
versionFlag = flag.Bool("version", false, "print Anubis version")
|
versionFlag = flag.Bool("version", false, "print Anubis version")
|
||||||
publicUrl = flag.String("public-url", "", "the externally accessible URL for this Anubis instance, used for constructing redirect URLs (e.g., for forwardAuth).")
|
publicUrl = flag.String("public-url", "", "the externally accessible URL for this Anubis instance, used for constructing redirect URLs (e.g., for forwardAuth).")
|
||||||
xffStripPrivate = flag.Bool("xff-strip-private", true, "if set, strip private addresses from X-Forwarded-For")
|
xffStripPrivate = flag.Bool("xff-strip-private", true, "if set, strip private addresses from X-Forwarded-For")
|
||||||
customRealIPHeader = flag.String("custom-real-ip-header", "", "if set, read remote IP from header of this name (in case your environment doesn't set X-Real-IP header)")
|
customRealIPHeader = flag.String("custom-real-ip-header", "", "if set, read remote IP from header of this name (in case your environment doesn't set X-Real-IP header)")
|
||||||
|
|
||||||
thothInsecure = flag.Bool("thoth-insecure", false, "if set, connect to Thoth over plain HTTP/2, don't enable this unless support told you to")
|
thothInsecure = flag.Bool("thoth-insecure", false, "if set, connect to Thoth over plain HTTP/2, don't enable this unless support told you to")
|
||||||
thothURL = flag.String("thoth-url", "", "if set, URL for Thoth, the IP reputation database for Anubis")
|
thothURL = flag.String("thoth-url", "", "if set, URL for Thoth, the IP reputation database for Anubis")
|
||||||
@@ -145,19 +145,19 @@ func parseBindNetFromAddr(address string) (string, string) {
|
|||||||
return "", address
|
return "", address
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSameSite(s string) http.SameSite {
|
func parseSameSite(s string) (http.SameSite) {
|
||||||
switch strings.ToLower(s) {
|
switch strings.ToLower(s) {
|
||||||
case "none":
|
case "none":
|
||||||
return http.SameSiteNoneMode
|
return http.SameSiteNoneMode
|
||||||
case "lax":
|
case "lax":
|
||||||
return http.SameSiteLaxMode
|
return http.SameSiteLaxMode
|
||||||
case "strict":
|
case "strict":
|
||||||
return http.SameSiteStrictMode
|
return http.SameSiteStrictMode
|
||||||
case "default":
|
case "default":
|
||||||
return http.SameSiteDefaultMode
|
return http.SameSiteDefaultMode
|
||||||
default:
|
default:
|
||||||
log.Fatalf("invalid cookie same-site mode: %s, valid values are None, Lax, Strict, and Default", s)
|
log.Fatalf("invalid cookie same-site mode: %s, valid values are None, Lax, Strict, and Default", s)
|
||||||
}
|
}
|
||||||
return http.SameSiteDefaultMode
|
return http.SameSiteDefaultMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
<!-- This changes the project to: -->
|
<!-- This changes the project to: -->
|
||||||
|
|
||||||
- Fix panic when validating challenges after privacy-mode browsers strip headers and the follow-up request matches an `ALLOW` threshold.
|
|
||||||
- Expose WEIGHT rule matches as Prometheus metrics.
|
- Expose WEIGHT rule matches as Prometheus metrics.
|
||||||
- Allow more OCI registry clients [based on feedback](https://github.com/TecharoHQ/anubis/pull/1253#issuecomment-3506744184).
|
- Allow more OCI registry clients [based on feedback](https://github.com/TecharoHQ/anubis/pull/1253#issuecomment-3506744184).
|
||||||
- Expose services directory in the embedded `(data)` filesystem.
|
- Expose services directory in the embedded `(data)` filesystem.
|
||||||
@@ -21,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Allow Renovate as an OCI registry client.
|
- Allow Renovate as an OCI registry client.
|
||||||
- Properly handle 4in6 addresses so that IP matching works with those addresses.
|
- Properly handle 4in6 addresses so that IP matching works with those addresses.
|
||||||
- Add support to simple Valkey/Redis cluster mode
|
- Add support to simple Valkey/Redis cluster mode
|
||||||
|
- Bump the Playwright dev dependency to 1.56.0
|
||||||
|
|
||||||
## v1.23.1: Lyse Hext - Echo 1
|
## v1.23.1: Lyse Hext - Echo 1
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ const (
|
|||||||
actionChallenge action = "CHALLENGE"
|
actionChallenge action = "CHALLENGE"
|
||||||
|
|
||||||
placeholderIP = "fd11:5ee:bad:c0de::"
|
placeholderIP = "fd11:5ee:bad:c0de::"
|
||||||
playwrightVersion = "1.52.0"
|
playwrightVersion = "1.56.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
type action string
|
type action string
|
||||||
|
|||||||
@@ -117,12 +117,10 @@ func (s *Server) issueChallenge(ctx context.Context, r *http.Request, lg *slog.L
|
|||||||
}
|
}
|
||||||
|
|
||||||
chall := challenge.Challenge{
|
chall := challenge.Challenge{
|
||||||
ID: id.String(),
|
ID: id.String(),
|
||||||
Method: rule.Challenge.Algorithm,
|
Method: rule.Challenge.Algorithm,
|
||||||
RandomData: fmt.Sprintf("%x", randomData),
|
RandomData: fmt.Sprintf("%x", randomData),
|
||||||
IssuedAt: time.Now(),
|
IssuedAt: time.Now(),
|
||||||
Difficulty: rule.Challenge.Difficulty,
|
|
||||||
PolicyRuleHash: rule.Hash(),
|
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"User-Agent": r.Header.Get("User-Agent"),
|
"User-Agent": r.Header.Get("User-Agent"),
|
||||||
"X-Real-Ip": r.Header.Get("X-Real-Ip"),
|
"X-Real-Ip": r.Header.Get("X-Real-Ip"),
|
||||||
@@ -139,44 +137,6 @@ func (s *Server) issueChallenge(ctx context.Context, r *http.Request, lg *slog.L
|
|||||||
return &chall, err
|
return &chall, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) hydrateChallengeRule(rule *policy.Bot, chall *challenge.Challenge, lg *slog.Logger) *policy.Bot {
|
|
||||||
if chall == nil {
|
|
||||||
return rule
|
|
||||||
}
|
|
||||||
|
|
||||||
if rule == nil {
|
|
||||||
rule = &policy.Bot{
|
|
||||||
Rules: &checker.List{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if chall.Difficulty == 0 {
|
|
||||||
// fall back to whatever the policy currently says or the global default
|
|
||||||
if rule.Challenge != nil && rule.Challenge.Difficulty != 0 {
|
|
||||||
chall.Difficulty = rule.Challenge.Difficulty
|
|
||||||
} else {
|
|
||||||
chall.Difficulty = s.policy.DefaultDifficulty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rule.Challenge == nil {
|
|
||||||
lg.Warn("rule missing challenge configuration; using stored challenge metadata", "rule", rule.Name)
|
|
||||||
rule.Challenge = &config.ChallengeRules{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rule.Challenge.Difficulty == 0 {
|
|
||||||
rule.Challenge.Difficulty = chall.Difficulty
|
|
||||||
}
|
|
||||||
if rule.Challenge.ReportAs == 0 {
|
|
||||||
rule.Challenge.ReportAs = chall.Difficulty
|
|
||||||
}
|
|
||||||
if rule.Challenge.Algorithm == "" {
|
|
||||||
rule.Challenge.Algorithm = chall.Method
|
|
||||||
}
|
|
||||||
|
|
||||||
return rule
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) maybeReverseProxyHttpStatusOnly(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) maybeReverseProxyHttpStatusOnly(w http.ResponseWriter, r *http.Request) {
|
||||||
s.maybeReverseProxy(w, r, true)
|
s.maybeReverseProxy(w, r, true)
|
||||||
}
|
}
|
||||||
@@ -501,8 +461,6 @@ func (s *Server) PassChallenge(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rule = s.hydrateChallengeRule(rule, chall, lg)
|
|
||||||
|
|
||||||
impl, ok := challenge.Get(chall.Method)
|
impl, ok := challenge.Get(chall.Method)
|
||||||
if !ok {
|
if !ok {
|
||||||
lg.Error("check failed", "err", err)
|
lg.Error("check failed", "err", err)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package lib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -19,10 +18,8 @@ import (
|
|||||||
"github.com/TecharoHQ/anubis"
|
"github.com/TecharoHQ/anubis"
|
||||||
"github.com/TecharoHQ/anubis/data"
|
"github.com/TecharoHQ/anubis/data"
|
||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
"github.com/TecharoHQ/anubis/lib/challenge"
|
|
||||||
"github.com/TecharoHQ/anubis/lib/policy"
|
"github.com/TecharoHQ/anubis/lib/policy"
|
||||||
"github.com/TecharoHQ/anubis/lib/policy/config"
|
"github.com/TecharoHQ/anubis/lib/policy/config"
|
||||||
"github.com/TecharoHQ/anubis/lib/store"
|
|
||||||
"github.com/TecharoHQ/anubis/lib/thoth/thothmock"
|
"github.com/TecharoHQ/anubis/lib/thoth/thothmock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1030,59 +1027,6 @@ func TestPassChallengeXSS(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPassChallengeNilRuleChallengeFallback(t *testing.T) {
|
|
||||||
pol := loadPolicies(t, "testdata/zero_difficulty.yaml", 0)
|
|
||||||
|
|
||||||
srv := spawnAnubis(t, Options{
|
|
||||||
Next: http.NewServeMux(),
|
|
||||||
Policy: pol,
|
|
||||||
})
|
|
||||||
|
|
||||||
allowThreshold, err := policy.ParsedThresholdFromConfig(config.Threshold{
|
|
||||||
Name: "allow-all",
|
|
||||||
Expression: &config.ExpressionOrList{
|
|
||||||
Expression: "true",
|
|
||||||
},
|
|
||||||
Action: config.RuleAllow,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("can't compile test threshold: %v", err)
|
|
||||||
}
|
|
||||||
srv.policy.Thresholds = []*policy.Threshold{allowThreshold}
|
|
||||||
srv.policy.Bots = nil
|
|
||||||
|
|
||||||
chall := challenge.Challenge{
|
|
||||||
ID: "test-challenge",
|
|
||||||
Method: "metarefresh",
|
|
||||||
RandomData: "apple cider",
|
|
||||||
IssuedAt: time.Now().Add(-5 * time.Second),
|
|
||||||
Difficulty: 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
j := store.JSON[challenge.Challenge]{Underlying: srv.store}
|
|
||||||
if err := j.Set(context.Background(), "challenge:"+chall.ID, chall, time.Minute); err != nil {
|
|
||||||
t.Fatalf("can't insert challenge into store: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req := httptest.NewRequest(http.MethodGet, "https://example.com"+anubis.APIPrefix+"pass-challenge", nil)
|
|
||||||
q := req.URL.Query()
|
|
||||||
q.Set("redir", "/")
|
|
||||||
q.Set("id", chall.ID)
|
|
||||||
q.Set("challenge", chall.RandomData)
|
|
||||||
req.URL.RawQuery = q.Encode()
|
|
||||||
req.Header.Set("X-Real-Ip", "203.0.113.4")
|
|
||||||
req.Header.Set("User-Agent", "NilChallengeTester/1.0")
|
|
||||||
req.AddCookie(&http.Cookie{Name: anubis.TestCookieName, Value: chall.ID})
|
|
||||||
|
|
||||||
rr := httptest.NewRecorder()
|
|
||||||
|
|
||||||
srv.PassChallenge(rr, req)
|
|
||||||
|
|
||||||
if rr.Code != http.StatusFound {
|
|
||||||
t.Fatalf("expected redirect when validating challenge, got %d", rr.Code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestXForwardedForNoDoubleComma(t *testing.T) {
|
func TestXForwardedForNoDoubleComma(t *testing.T) {
|
||||||
var h http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
var h http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("X-Forwarded-For", r.Header.Get("X-Forwarded-For"))
|
w.Header().Set("X-Forwarded-For", r.Header.Get("X-Forwarded-For"))
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import "time"
|
|||||||
|
|
||||||
// Challenge is the metadata about a single challenge issuance.
|
// Challenge is the metadata about a single challenge issuance.
|
||||||
type Challenge struct {
|
type Challenge struct {
|
||||||
ID string `json:"id"` // UUID identifying the challenge
|
ID string `json:"id"` // UUID identifying the challenge
|
||||||
Method string `json:"method"` // Challenge method
|
Method string `json:"method"` // Challenge method
|
||||||
RandomData string `json:"randomData"` // The random data the client processes
|
RandomData string `json:"randomData"` // The random data the client processes
|
||||||
IssuedAt time.Time `json:"issuedAt"` // When the challenge was issued
|
IssuedAt time.Time `json:"issuedAt"` // When the challenge was issued
|
||||||
Metadata map[string]string `json:"metadata"` // Challenge metadata such as IP address and user agent
|
Metadata map[string]string `json:"metadata"` // Challenge metadata such as IP address and user agent
|
||||||
Spent bool `json:"spent"` // Has the challenge already been solved?
|
Spent bool `json:"spent"` // Has the challenge already been solved?
|
||||||
Difficulty int `json:"difficulty,omitempty"` // Difficulty that was in effect when issued
|
|
||||||
PolicyRuleHash string `json:"policyRuleHash,omitempty"` // Hash of the policy rule that issued this challenge
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/TecharoHQ/anubis"
|
|
||||||
"github.com/TecharoHQ/anubis/internal"
|
"github.com/TecharoHQ/anubis/internal"
|
||||||
"github.com/TecharoHQ/anubis/lib/challenge"
|
"github.com/TecharoHQ/anubis/lib/challenge"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -20,6 +19,5 @@ func New(t *testing.T) *challenge.Challenge {
|
|||||||
ID: id.String(),
|
ID: id.String(),
|
||||||
RandomData: randomData,
|
RandomData: randomData,
|
||||||
IssuedAt: time.Now(),
|
IssuedAt: time.Now(),
|
||||||
Difficulty: anubis.DefaultDifficulty,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func TestLocalizationService(t *testing.T) {
|
|||||||
"vi": "Đang nạp...",
|
"vi": "Đang nạp...",
|
||||||
"zh-CN": "加载中...",
|
"zh-CN": "加载中...",
|
||||||
"zh-TW": "載入中...",
|
"zh-TW": "載入中...",
|
||||||
"sv": "Laddar...",
|
"sv" : "Laddar...",
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys []string
|
var keys []string
|
||||||
|
|||||||
16
package-lock.json
generated
16
package-lock.json
generated
@@ -16,7 +16,7 @@
|
|||||||
"cssnano": "^7.1.2",
|
"cssnano": "^7.1.2",
|
||||||
"cssnano-preset-advanced": "^7.0.10",
|
"cssnano-preset-advanced": "^7.0.10",
|
||||||
"esbuild": "^0.25.12",
|
"esbuild": "^0.25.12",
|
||||||
"playwright": "^1.52.0",
|
"playwright": "^1.56.0",
|
||||||
"postcss-cli": "^11.0.1",
|
"postcss-cli": "^11.0.1",
|
||||||
"postcss-import": "^16.1.1",
|
"postcss-import": "^16.1.1",
|
||||||
"postcss-import-url": "^7.2.0",
|
"postcss-import-url": "^7.2.0",
|
||||||
@@ -1603,13 +1603,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/playwright": {
|
"node_modules/playwright": {
|
||||||
"version": "1.52.0",
|
"version": "1.56.1",
|
||||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.52.0.tgz",
|
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.56.1.tgz",
|
||||||
"integrity": "sha512-JAwMNMBlxJ2oD1kce4KPtMkDeKGHQstdpFPcPH3maElAXon/QZeTvtsfXmTMRyO9TslfoYOXkSsvao2nE1ilTw==",
|
"integrity": "sha512-aFi5B0WovBHTEvpM3DzXTUaeN6eN0qWnTkKx4NQaH4Wvcmc153PdaY2UBdSYKaGYw+UyWXSVyxDUg5DoPEttjw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"playwright-core": "1.52.0"
|
"playwright-core": "1.56.1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"playwright": "cli.js"
|
"playwright": "cli.js"
|
||||||
@@ -1622,9 +1622,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/playwright-core": {
|
"node_modules/playwright-core": {
|
||||||
"version": "1.52.0",
|
"version": "1.56.1",
|
||||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.52.0.tgz",
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.56.1.tgz",
|
||||||
"integrity": "sha512-l2osTgLXSMeuLZOML9qYODUQoPPnUsKsb5/P6LJ2e6uPKXUdPK5WYhN4z03G+YNbWmGDY4YENauNu4ZKczreHg==",
|
"integrity": "sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"cssnano": "^7.1.2",
|
"cssnano": "^7.1.2",
|
||||||
"cssnano-preset-advanced": "^7.0.10",
|
"cssnano-preset-advanced": "^7.0.10",
|
||||||
"esbuild": "^0.25.12",
|
"esbuild": "^0.25.12",
|
||||||
"playwright": "^1.52.0",
|
"playwright": "^1.56.0",
|
||||||
"postcss-cli": "^11.0.1",
|
"postcss-cli": "^11.0.1",
|
||||||
"postcss-import": "^16.1.1",
|
"postcss-import": "^16.1.1",
|
||||||
"postcss-import-url": "^7.2.0",
|
"postcss-import-url": "^7.2.0",
|
||||||
@@ -31,4 +31,4 @@
|
|||||||
"@aws-crypto/sha256-js": "^5.2.0",
|
"@aws-crypto/sha256-js": "^5.2.0",
|
||||||
"preact": "^10.27.2"
|
"preact": "^10.27.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user