fix(cabana): allow in-process backend dispatch through CSRF guard
This commit is contained in:
@@ -64,6 +64,31 @@ func TestPhase10CSRF(t *testing.T) {
|
||||
if rec.Code == http.StatusForbidden {
|
||||
t.Fatalf("Bearer request was refused: %s", rec.Body.String())
|
||||
}
|
||||
|
||||
// In-process backend dispatch (e.g. pier MCP tool calls) has no
|
||||
// Authorization or X-Requested-With header and must pass CSRF.
|
||||
withDispatch, _ := csrfRequest(method, path, super)
|
||||
withDispatch = withDispatch.WithContext(bouncer.WithDispatch(withDispatch.Context(), &bouncer.Dispatch{
|
||||
Guards: []string{"backend"},
|
||||
Principal: super,
|
||||
}))
|
||||
rec = httptest.NewRecorder()
|
||||
handler(rec, withDispatch)
|
||||
if rec.Code == http.StatusForbidden {
|
||||
t.Fatalf("in-process backend dispatch was refused: %s", rec.Body.String())
|
||||
}
|
||||
|
||||
// Non-backend dispatch marker must NOT bypass admin CSRF.
|
||||
wrongDispatch, _ := csrfRequest(method, path, super)
|
||||
wrongDispatch = wrongDispatch.WithContext(bouncer.WithDispatch(wrongDispatch.Context(), &bouncer.Dispatch{
|
||||
Guards: []string{"api"},
|
||||
Principal: super,
|
||||
}))
|
||||
rec = httptest.NewRecorder()
|
||||
handler(rec, wrongDispatch)
|
||||
if rec.Code != http.StatusForbidden {
|
||||
t.Fatalf("non-backend dispatch status=%d, want 403", rec.Code)
|
||||
}
|
||||
})
|
||||
}
|
||||
// refresh, logout, account update, preferences update, avatar upload and remove, account
|
||||
|
||||
Reference in New Issue
Block a user