mirror of
https://github.com/TecharoHQ/anubis.git
synced 2026-05-20 05:10:30 +00:00
fix(policy): mend an edge case with subrequest auth and query strings
This fixes an unlikely edge case where using subrequest auth and query strings with path based filtering can cause reality to differ from administrator intent. This effectively strips the query string from subrequest auth checks. This deficiency should be fixed in the future. Ref: AWOO-004 Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Log weight when issuing challenge.
|
- Log weight when issuing challenge.
|
||||||
- Gate pprof endpoints behind `metrics.debug` in the policy file.
|
- Gate pprof endpoints behind `metrics.debug` in the policy file.
|
||||||
- Limit naive honeypot r9k delay to one second.
|
- Limit naive honeypot r9k delay to one second.
|
||||||
|
- Fix an obscure case where adding query values to a subrequest match could cause an invalid rule match when using path based matching for protected resources.
|
||||||
- Fix `path_regex` and CEL `path` rules not matching when using Traefik `forwardAuth` middleware. Anubis now checks `X-Forwarded-Uri` (Traefik) in addition to `X-Original-URI` (nginx) when resolving the request path in subrequest mode ([#1628](https://github.com/TecharoHQ/anubis/issues/1628)).
|
- Fix `path_regex` and CEL `path` rules not matching when using Traefik `forwardAuth` middleware. Anubis now checks `X-Forwarded-Uri` (Traefik) in addition to `X-Original-URI` (nginx) when resolving the request path in subrequest mode ([#1628](https://github.com/TecharoHQ/anubis/issues/1628)).
|
||||||
|
|
||||||
## v1.25.0: Necron
|
## v1.25.0: Necron
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -114,6 +115,9 @@ func (pc *PathChecker) Check(r *http.Request) (bool, error) {
|
|||||||
originalUrl = r.Header.Get("X-Forwarded-Uri")
|
originalUrl = r.Header.Get("X-Forwarded-Uri")
|
||||||
}
|
}
|
||||||
if originalUrl != "" {
|
if originalUrl != "" {
|
||||||
|
if parsed, err := url.ParseRequestURI(originalUrl); err == nil {
|
||||||
|
originalUrl = parsed.Path
|
||||||
|
}
|
||||||
if pc.regexp.MatchString(originalUrl) {
|
if pc.regexp.MatchString(originalUrl) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package policy
|
package policy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -85,3 +87,27 @@ func TestBadConfigs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPathCheckerStripsForwardedURIQuery(t *testing.T) {
|
||||||
|
checker, err := NewPathChecker("^/admin$", true)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "https://anubis.local/.within.website/x/cmd/anubis/api/check", nil)
|
||||||
|
req.Header.Set("X-Forwarded-Uri", "/admin?x=1")
|
||||||
|
matched, err := checker.Check(req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !matched {
|
||||||
|
t.Fatalf("expected exact path checker to match forwarded URI when query string is appended")
|
||||||
|
}
|
||||||
|
req.Header.Set("X-Forwarded-Uri", "/admin")
|
||||||
|
matched, err = checker.Check(req)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !matched {
|
||||||
|
t.Fatalf("expected exact path checker to match forwarded URI without query string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user