Skip to content

Commit 5b2a69f

Browse files
committed
Fixed allowed path match using wcmatch
1 parent 4d91a1d commit 5b2a69f

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
authors = [{ name = "Aman Rusia", email = "[email protected]" }]
33
name = "wcgw"
4-
version = "5.4.4"
4+
version = "5.4.5"
55
description = "Shell and coding agent for Claude and other mcp clients"
66
readme = "README.md"
77
requires-python = ">=3.11"
@@ -27,6 +27,7 @@ dependencies = [
2727
"tree-sitter>=0.24.0",
2828
"tree-sitter-bash>=0.23.3",
2929
"mcp>=1.7.0",
30+
"wcmatch>=10.1",
3031
]
3132

3233
[project.urls]

src/wcgw/client/tools.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import base64
2-
import fnmatch
32
import glob
43
import json
54
import mimetypes
@@ -29,6 +28,7 @@
2928
from pydantic import BaseModel, TypeAdapter, ValidationError
3029
from syntax_checker import Output as SCOutput
3130
from syntax_checker import check_syntax as raw_check_syntax
31+
from wcmatch import glob as wcglob
3232

3333
from ..client.bash_state.bash_state import (
3434
BashState,
@@ -570,8 +570,8 @@ def write_file(
570570

571571
# Validate using write_if_empty_mode after checking whitelist
572572
allowed_globs = context.bash_state.write_if_empty_mode.allowed_globs
573-
if allowed_globs != "all" and not any(
574-
fnmatch.fnmatch(path_, pattern) for pattern in allowed_globs
573+
if allowed_globs != "all" and not wcglob.globmatch(
574+
path_, allowed_globs, flags=wcglob.GLOBSTAR
575575
):
576576
return (
577577
f"Error: updating file {path_} not allowed in current mode. Doesn't match allowed globs: {allowed_globs}",
@@ -762,8 +762,8 @@ def _do_diff_edit(
762762

763763
# Validate using file_edit_mode
764764
allowed_globs = context.bash_state.file_edit_mode.allowed_globs
765-
if allowed_globs != "all" and not any(
766-
fnmatch.fnmatch(path_, pattern) for pattern in allowed_globs
765+
if allowed_globs != "all" and not wcglob.globmatch(
766+
path_, allowed_globs, flags=wcglob.GLOBSTAR
767767
):
768768
raise Exception(
769769
f"Error: updating file {path_} not allowed in current mode. Doesn't match allowed globs: {allowed_globs}"

uv.lock

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)