fix(security): block refresh tokens as bearer and sandbox MCP uploads

Reject refresh JWTs in ValidateToken, revoke all user sessions on logout,
and restrict create_knowledge_from_file to allowed directories on network MCP transports.
This commit is contained in:
wizardchen
2026-07-02 15:26:43 +08:00
committed by lyingbug
parent cd65665894
commit 040504447e
7 changed files with 180 additions and 3 deletions
@@ -6,6 +6,25 @@ import (
"github.com/golang-jwt/jwt/v5"
)
func TestIsRefreshTokenClaims(t *testing.T) {
cases := []struct {
name string
claims jwt.MapClaims
want bool
}{
{name: "refresh", claims: jwt.MapClaims{"type": "refresh"}, want: true},
{name: "access", claims: jwt.MapClaims{"type": "access"}, want: false},
{name: "missing type", claims: jwt.MapClaims{"user_id": "u1"}, want: false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := isRefreshTokenClaims(tc.claims); got != tc.want {
t.Fatalf("isRefreshTokenClaims(%v) = %v, want %v", tc.claims, got, tc.want)
}
})
}
}
// tenantIDFromClaims is the JWT->tenant-id projection used by
// userService.ValidateToken. It must:
// - prefer the claim when present (so /auth/switch-tenant takes effect)