[Bug]: request-rewrite ReplacePrefixMatch treats "/api" as a prefix of "/api2/...", and drops a slash when the operation path ends with "/"
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- backend-api-design
Direzione di ricerca
L’issue indica policies/request-rewrite/requestrewrite.go e fornisce due test di regressione per applyPathRewrite. Inizia leggendo quella funzione ed esegui il comando go test indicato in policies/request-rewrite. Il lavoro è completato quando /api lascia /api2/users invariato e /api/ riscrive /api/users in /v2/users; aggiungi test per entrambi i casi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
applyPathRewrite for ReplacePrefixMatch (wso2/gateway-controllers, policies/request-rewrite/requestrewrite.go) decides whether to rewrite with a raw string prefix check:
if !strings.HasPrefix(currentPath, operationPath) {
return currentPath
}
remainder := strings.TrimPrefix(currentPath, operationPath)
return cfg.ReplacePrefixMatch + remainder
That is not path-segment aware. Measured failures on main (4cf9570):
| operationPath | currentPath | ReplacePrefixMatch | Actual result | Expected |
|---|---|---|---|---|
/api |
/api2/users |
/v2 |
/v22/users |
unchanged /api2/users |
/api |
/api/users |
/v2 |
/v2/users |
/v2/users (OK) |
/api/ |
/api/users |
/v2 |
/v2users |
/v2/users |
So a short resource prefix silently rewrites longer sibling paths (/api vs /api2), and an operation path that ends with / concatenates without keeping a path separator. Envoy and most gateways treat prefix rewrite as a path-prefix match that ends on a / or end-of-path boundary.
Steps to Reproduce
Under policies/request-rewrite on 4cf9570:
func TestReplacePrefixMatchOverlappingPath(t *testing.T) {
cfg := &pathRewrite{Type: "REPLACEPREFIXMATCH", ReplacePrefixMatch: "/v2"}
got := applyPathRewrite("/api", "/api2/users", cfg)
if got != "/api2/users" {
t.Fatalf("prefix /api must not match /api2/users; got %q", got)
}
}
func TestReplacePrefixMatchTrailingSlashOnOperation(t *testing.T) {
cfg := &pathRewrite{Type: "REPLACEPREFIXMATCH", ReplacePrefixMatch: "/v2"}
got := applyPathRewrite("/api/", "/api/users", cfg)
if got != "/v2/users" {
t.Fatalf("got %q want /v2/users", got)
}
}
go test -run 'TestReplacePrefixMatchOverlapping|TestReplacePrefixMatchTrailing' -v .
Severity Level of the Issue
Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)
Environment Details (with versions)
- wso2/gateway-controllers main
4cf9570(request-rewrite policy; sdk/core as in that module'sgo.mod) - Go 1.26.x, Linux x86_64
Related Issues
#1297 covers invalid regex / unsupported type silent no-op and query reordering. It does not mention prefix-boundary or trailing-slash concatenation. No other open issue found for ReplacePrefixMatch overlapping paths.
Possible Solution
- Match only when
currentPath == operationPathorcurrentPathcontinues with/after the operation prefix (after normalizing a trailing/on the operation path). - When joining
ReplacePrefixMatchand the remainder, ensure exactly one/between them. - Add the two regression tests above.
op := strings.TrimSuffix(operationPath, "/")
if currentPath != op && !strings.HasPrefix(currentPath, op+"/") {
return currentPath
}
remainder := strings.TrimPrefix(currentPath, op)
repl := strings.TrimSuffix(cfg.ReplacePrefixMatch, "/")
if remainder == "" {
return repl
}
return repl + remainder
I'm happy to send a PR.
- Lingua principale
- Go
- Stelle
- 79
- Fork
- 130
- Merge medio
- 2g 51m
- PR unite (30g)
- 173
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di wso2/api-platform
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
wso2/api-platform#3917 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
wso2/api-platform#3916 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: ap gateway image build cannot find local policies on WindowsForse già presa @Jayzilva l’ha presa 4 giorni fa. ApertaAspect/Configuration Severity/Major
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
wso2/api-platform#3912 ·
I maintainer di solito rispondono entro 1 giorno
-
Aspect/API Severity/Minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
wso2/api-platform#3909 ·
I maintainer di solito rispondono entro 1 giorno
-
Aspect/API Aspect/UI Severity/Minor Type/Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
wso2/api-platform#3904 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di wso2/api-platform
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
yetone/magpie#4095 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
docs: Google Safe Browsing flags go-bonnie.dev as "deceptive" (pipe-to-shell install instructions)Apertadocumentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
[Bug]: Telegram bot (v3.11.0): "Ban log" no longer sends the current 3xipl-banned.logForse già presa @HamedSanaei l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
MHSanaei/3x-ui#6990 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
bug(tool/internal/instrument): identical inject_code rules from two rule packages are applied twiceAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
open-telemetry/opentelemetry-go-compile-instrumentation#1611 ·
I maintainer di solito rispondono entro 2 giorni