@@ -316,6 +316,36 @@ func validateArgs(params map[string]string, entry ToolEntry) (bool, string) {
316316// Core evaluation
317317// ---------------------------------------------------------------------------
318318
319+ // checkPathConstraints validates path parameters against allowlist/denylist rules.
320+ func checkPathConstraints (params map [string ]string , entry ToolEntry ) (bool , string ) {
321+ path , ok := params ["path" ]
322+ if ! ok || path == "" {
323+ return true , ""
324+ }
325+
326+ resolved , err := cleanAndResolvePath (path )
327+ if err != nil {
328+ return false , "invalid path: " + err .Error ()
329+ }
330+
331+ for _ , denied := range entry .PathsDenylist {
332+ if matchesGlob (resolved , denied ) {
333+ return false , "path matches denylist"
334+ }
335+ }
336+
337+ if len (entry .PathsAllowlist ) > 0 {
338+ for _ , pattern := range entry .PathsAllowlist {
339+ if matchesGlob (resolved , pattern ) {
340+ return true , ""
341+ }
342+ }
343+ return false , "path not in allowlist"
344+ }
345+
346+ return true , ""
347+ }
348+
319349func evaluateTool (req ToolCallRequest ) ToolCallResponse {
320350 pol := getPolicy ()
321351
@@ -344,38 +374,12 @@ func evaluateTool(req ToolCallRequest) ToolCallResponse {
344374 return ToolCallResponse {Allowed : false , Reason : "tool not in allowlist" }
345375 }
346376
347- // Validate arguments
348377 if ok , reason := validateArgs (req .Params , * matched ); ! ok {
349378 return ToolCallResponse {Allowed : false , Reason : reason }
350379 }
351380
352- // Check path constraints
353- if path , ok := req .Params ["path" ]; ok && path != "" {
354- resolved , err := cleanAndResolvePath (path )
355- if err != nil {
356- return ToolCallResponse {Allowed : false , Reason : "invalid path: " + err .Error ()}
357- }
358-
359- // Check denylist first
360- for _ , denied := range matched .PathsDenylist {
361- if matchesGlob (resolved , denied ) {
362- return ToolCallResponse {Allowed : false , Reason : "path matches denylist" }
363- }
364- }
365-
366- // Check allowlist
367- if len (matched .PathsAllowlist ) > 0 {
368- pathAllowed := false
369- for _ , pattern := range matched .PathsAllowlist {
370- if matchesGlob (resolved , pattern ) {
371- pathAllowed = true
372- break
373- }
374- }
375- if ! pathAllowed {
376- return ToolCallResponse {Allowed : false , Reason : "path not in allowlist" }
377- }
378- }
381+ if ok , reason := checkPathConstraints (req .Params , * matched ); ! ok {
382+ return ToolCallResponse {Allowed : false , Reason : reason }
379383 }
380384
381385 return ToolCallResponse {Allowed : true }
0 commit comments