zerochat 10.28.0__tar.gz → 10.30.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zerochat-10.28.0/zerochat.egg-info → zerochat-10.30.0}/PKG-INFO +1 -1
- {zerochat-10.28.0 → zerochat-10.30.0}/pyproject.toml +1 -1
- {zerochat-10.28.0 → zerochat-10.30.0/zerochat.egg-info}/PKG-INFO +1 -1
- {zerochat-10.28.0 → zerochat-10.30.0}/zerochat.py +96 -72
- {zerochat-10.28.0 → zerochat-10.30.0}/LICENSE +0 -0
- {zerochat-10.28.0 → zerochat-10.30.0}/README.md +0 -0
- {zerochat-10.28.0 → zerochat-10.30.0}/setup.cfg +0 -0
- {zerochat-10.28.0 → zerochat-10.30.0}/zerochat.egg-info/SOURCES.txt +0 -0
- {zerochat-10.28.0 → zerochat-10.30.0}/zerochat.egg-info/dependency_links.txt +0 -0
- {zerochat-10.28.0 → zerochat-10.30.0}/zerochat.egg-info/entry_points.txt +0 -0
- {zerochat-10.28.0 → zerochat-10.30.0}/zerochat.egg-info/top_level.txt +0 -0
|
@@ -1575,7 +1575,7 @@ def dispatch_browser(method: str, params: dict) -> RpcOutcome:
|
|
|
1575
1575
|
|
|
1576
1576
|
|
|
1577
1577
|
|
|
1578
|
-
SOURCE_BACKEND_VERSION = "10.
|
|
1578
|
+
SOURCE_BACKEND_VERSION = "10.30.0"
|
|
1579
1579
|
|
|
1580
1580
|
|
|
1581
1581
|
def _read_source_version(filename: str) -> str | None:
|
|
@@ -2312,11 +2312,17 @@ class SecurityContext:
|
|
|
2312
2312
|
Es la misma que evalúan los permisos (resolve_path): colapsa los '..' antes de seguir enlaces
|
|
2313
2313
|
simbólicos, así 'enlace/../x' no se permite como una ruta y se abre como otra. ValueError si no es válida.
|
|
2314
2314
|
"""
|
|
2315
|
-
|
|
2315
|
+
raw = str(path).strip()
|
|
2316
|
+
if not raw or "\0" in raw:
|
|
2317
|
+
raise ValueError(f"Ruta no válida: '{path}'.")
|
|
2318
|
+
expanded = Path(raw).expanduser()
|
|
2319
|
+
if contains_unresolved_reference(str(expanded)):
|
|
2320
|
+
raise ValueError(f"Ruta no válida: '{path}'.")
|
|
2321
|
+
candidate = expanded if expanded.is_absolute() else self.workspace_dir / expanded
|
|
2322
|
+
norm = normalize_directory_path(str(candidate))
|
|
2316
2323
|
if not norm:
|
|
2317
2324
|
raise ValueError(f"Ruta no válida: '{path}'.")
|
|
2318
|
-
|
|
2319
|
-
return (target if target.is_absolute() else self.workspace_dir / target).resolve()
|
|
2325
|
+
return Path(norm).resolve()
|
|
2320
2326
|
|
|
2321
2327
|
def resolve_path(self, path_str: str) -> Path | None:
|
|
2322
2328
|
"""La ruta de absolute() para evaluar permisos; None si no es válida o lleva referencias sin resolver ('~', '$VAR')."""
|
|
@@ -2392,7 +2398,7 @@ POLICY_ASK = "ask"
|
|
|
2392
2398
|
SCOPE_PERMANENT = "permanent"
|
|
2393
2399
|
SCOPE_SESSION = "session"
|
|
2394
2400
|
AUTHORIZE_DECISIONS = ("allow_once", "allow_session", "allow_project", "allow_always", "allow_server_always")
|
|
2395
|
-
DIRECTORY_RULE_PATTERN = re.compile(r"^(
|
|
2401
|
+
DIRECTORY_RULE_PATTERN = re.compile(r"^([RWX]+):(.+)$")
|
|
2396
2402
|
COMMAND_TOOL = "run_command"
|
|
2397
2403
|
JOB_CONTROL_TOOL = "check_command"
|
|
2398
2404
|
# Herramientas integradas que acceden al sistema de archivos por su argumento de ruta.
|
|
@@ -2427,13 +2433,16 @@ _COMMAND_INTERNAL_OUTSIDE_REF = re.compile(r"[\s:'\"](?:[\\/~]|[A-Za-z]:[\\/]|\.
|
|
|
2427
2433
|
|
|
2428
2434
|
|
|
2429
2435
|
def parse_directory_rule(raw_rule: str) -> dict | None:
|
|
2430
|
-
"""Parsea una regla '
|
|
2436
|
+
"""Parsea una regla '<permisos>:path' (combinación sin repetidos de R, W, X) normalizando su ruta."""
|
|
2431
2437
|
if not isinstance(raw_rule, str):
|
|
2432
2438
|
return None
|
|
2433
2439
|
match = DIRECTORY_RULE_PATTERN.match(raw_rule.strip())
|
|
2434
2440
|
if not match:
|
|
2435
2441
|
return None
|
|
2436
|
-
|
|
2442
|
+
raw_access = match.group(1)
|
|
2443
|
+
if len(set(raw_access)) != len(raw_access):
|
|
2444
|
+
return None
|
|
2445
|
+
access = "".join(ch for ch in ("R", "W", "X") if ch in raw_access)
|
|
2437
2446
|
raw_path = match.group(2)
|
|
2438
2447
|
path = normalize_directory_path(raw_path)
|
|
2439
2448
|
if not path:
|
|
@@ -3586,6 +3595,15 @@ def secret_names(prefix: str) -> set[str]:
|
|
|
3586
3595
|
SERVER_ID_KEY = "system:server_id"
|
|
3587
3596
|
|
|
3588
3597
|
|
|
3598
|
+
def conversations_revision() -> str:
|
|
3599
|
+
"""Firma ligera del estado de conversaciones en SQLite para detectar cambios externos."""
|
|
3600
|
+
with open_storage() as conn:
|
|
3601
|
+
row = conn.execute(
|
|
3602
|
+
"SELECT COUNT(*) AS n, COALESCE(MAX(updated_at), 0) AS m, COALESCE(SUM(updated_at), 0) AS s FROM conversations;"
|
|
3603
|
+
).fetchone()
|
|
3604
|
+
return f"{row['n']}:{row['m']}:{int(row['s'])}"
|
|
3605
|
+
|
|
3606
|
+
|
|
3589
3607
|
def get_server_id() -> str:
|
|
3590
3608
|
"""Identificador único y persistente de este servidor en SQLite."""
|
|
3591
3609
|
with _STORAGE_LOCK:
|
|
@@ -6665,7 +6683,7 @@ class AccessController:
|
|
|
6665
6683
|
dir_rules = {
|
|
6666
6684
|
str(project): list(rules)
|
|
6667
6685
|
for project, rules in raw_dir_rules.items()
|
|
6668
|
-
if isinstance(project, str) and isinstance(rules, list)
|
|
6686
|
+
if isinstance(project, str) and isinstance(rules, list)
|
|
6669
6687
|
} if isinstance(raw_dir_rules, dict) else {}
|
|
6670
6688
|
# run_command nunca se guarda autorizado entero: sus permisos permanentes son patrones.
|
|
6671
6689
|
tools = {tid: entry for tid, entry in dict(data.get("tools") or {}).items()
|
|
@@ -6690,15 +6708,18 @@ class AccessController:
|
|
|
6690
6708
|
def _effective_state(self, context: SecurityContext) -> dict:
|
|
6691
6709
|
"""Una sola lectura del estado permanente combinada con la capa de sesión del proyecto."""
|
|
6692
6710
|
state = self._read_permanent_state()
|
|
6711
|
+
default_rule = self.get_default_directory_rule(context)
|
|
6693
6712
|
with self._lock:
|
|
6694
6713
|
session = self._session(context)
|
|
6714
|
+
if session.directory_rules is not None:
|
|
6715
|
+
dir_rules = list(session.directory_rules)
|
|
6716
|
+
elif context.key in state["directoryRules"]:
|
|
6717
|
+
dir_rules = list(state["directoryRules"][context.key])
|
|
6718
|
+
else:
|
|
6719
|
+
dir_rules = [default_rule]
|
|
6695
6720
|
return {
|
|
6696
6721
|
"globalMcpPolicy": session.global_policy if session.global_policy is not None else state["globalMcpPolicy"],
|
|
6697
|
-
"directoryRules":
|
|
6698
|
-
list(session.directory_rules)
|
|
6699
|
-
if session.directory_rules is not None
|
|
6700
|
-
else list(state["directoryRules"].get(context.key) or [])
|
|
6701
|
-
),
|
|
6722
|
+
"directoryRules": dir_rules,
|
|
6702
6723
|
"tools": {**state["tools"], **session.tools},
|
|
6703
6724
|
"servers": {**state["servers"], **session.servers},
|
|
6704
6725
|
"commandPatterns": {**state["commandPatterns"], "session": list(session.command_patterns)}
|
|
@@ -6712,22 +6733,20 @@ class AccessController:
|
|
|
6712
6733
|
def export_state(self, context: SecurityContext) -> dict:
|
|
6713
6734
|
return {
|
|
6714
6735
|
"version": POLICY_STATE_VERSION,
|
|
6715
|
-
**self._effective_state(context)
|
|
6716
|
-
"defaultDirectoryRule": self.get_default_directory_rule(context)
|
|
6736
|
+
**self._effective_state(context)
|
|
6717
6737
|
}
|
|
6718
6738
|
|
|
6719
|
-
|
|
6739
|
+
@staticmethod
|
|
6740
|
+
def _validate_directory_rules(raw_rules: list | tuple) -> list[str]:
|
|
6720
6741
|
if not isinstance(raw_rules, (list, tuple)):
|
|
6721
6742
|
raise ValueError("Las reglas de directorio deben ser una lista.")
|
|
6722
6743
|
parsed_rules = []
|
|
6723
6744
|
for raw in raw_rules:
|
|
6724
6745
|
rule_obj = parse_directory_rule(raw)
|
|
6725
6746
|
if not rule_obj:
|
|
6726
|
-
raise ValueError(f"Regla de directorio inválida: '{raw}'. Formato esperado: R
|
|
6747
|
+
raise ValueError(f"Regla de directorio inválida: '{raw}'. Formato esperado: combinación de R, W y X (p. ej. R:path, RW:path, RWX:path).")
|
|
6727
6748
|
parsed_rules.append(rule_obj["rule"])
|
|
6728
|
-
|
|
6729
|
-
default_rule = self.get_default_directory_rule(context)
|
|
6730
|
-
return [r for r in unique_rules if r != default_rule]
|
|
6749
|
+
return list(dict.fromkeys(parsed_rules))
|
|
6731
6750
|
|
|
6732
6751
|
@staticmethod
|
|
6733
6752
|
def _validate_policy_entries(raw_entries: dict, kind: str, scope: str) -> dict:
|
|
@@ -6780,7 +6799,7 @@ class AccessController:
|
|
|
6780
6799
|
if total > MAX_POLICY_ENTRIES:
|
|
6781
6800
|
raise ValueError(f"El número total de entradas ({total}) supera el máximo permitido ({MAX_POLICY_ENTRIES}).")
|
|
6782
6801
|
|
|
6783
|
-
def _validate_state_payload(self, state: dict, scope: str
|
|
6802
|
+
def _validate_state_payload(self, state: dict, scope: str) -> tuple[str | None, list[str] | None, dict | None, dict | None]:
|
|
6784
6803
|
if not isinstance(state, dict):
|
|
6785
6804
|
raise ValueError("El estado de políticas debe ser un diccionario.")
|
|
6786
6805
|
|
|
@@ -6791,7 +6810,7 @@ class AccessController:
|
|
|
6791
6810
|
raise ValueError(f"Política global no válida: '{pol}'. Válidas: {GLOBAL_POLICIES}")
|
|
6792
6811
|
clean_global = pol
|
|
6793
6812
|
|
|
6794
|
-
clean_rules = self._validate_directory_rules(state["directoryRules"]
|
|
6813
|
+
clean_rules = self._validate_directory_rules(state["directoryRules"]) if "directoryRules" in state else None
|
|
6795
6814
|
clean_tools = self._validate_policy_entries(state["tools"], "tools", scope) if "tools" in state else None
|
|
6796
6815
|
clean_servers = self._validate_policy_entries(state["servers"], "servers", scope) if "servers" in state else None
|
|
6797
6816
|
return clean_global, clean_rules, clean_tools, clean_servers
|
|
@@ -6802,33 +6821,33 @@ class AccessController:
|
|
|
6802
6821
|
`addDirectoryRules` añade reglas a las guardadas dentro de la misma transacción y
|
|
6803
6822
|
`commandPatterns` sustituye los patrones de comando guardados.
|
|
6804
6823
|
"""
|
|
6805
|
-
clean_global, clean_rules, clean_tools, clean_servers = self._validate_state_payload(state, SCOPE_PERMANENT
|
|
6806
|
-
added_rules = self._validate_directory_rules(state["addDirectoryRules"]
|
|
6824
|
+
clean_global, clean_rules, clean_tools, clean_servers = self._validate_state_payload(state, SCOPE_PERMANENT)
|
|
6825
|
+
added_rules = self._validate_directory_rules(state["addDirectoryRules"]) if "addDirectoryRules" in state else []
|
|
6807
6826
|
clean_patterns = normalize_command_patterns(state["commandPatterns"]) if "commandPatterns" in state else None
|
|
6808
6827
|
|
|
6809
6828
|
project = context.key
|
|
6829
|
+
default_rule = self.get_default_directory_rule(context)
|
|
6810
6830
|
|
|
6811
6831
|
def mutator(current: dict) -> dict:
|
|
6812
|
-
self._apply_state_patch(current, project, clean_global, clean_rules, added_rules, clean_tools, clean_servers, clean_patterns)
|
|
6832
|
+
self._apply_state_patch(current, project, default_rule, clean_global, clean_rules, added_rules, clean_tools, clean_servers, clean_patterns)
|
|
6813
6833
|
self._check_entry_limit(current)
|
|
6814
6834
|
return current
|
|
6815
6835
|
self._update_permanent(mutator)
|
|
6816
6836
|
self._forget_session_overrides(project, clean_global, clean_rules, added_rules, clean_tools, clean_servers)
|
|
6817
6837
|
return self.export_state(context)
|
|
6818
6838
|
|
|
6819
|
-
def _apply_state_patch(self, current: dict, project: str, clean_global, clean_rules, added_rules, clean_tools, clean_servers, clean_patterns):
|
|
6839
|
+
def _apply_state_patch(self, current: dict, project: str, default_rule: str, clean_global, clean_rules, added_rules, clean_tools, clean_servers, clean_patterns):
|
|
6820
6840
|
"""Aplica sobre el estado guardado los apartados del parche que vienen (None es «no cambiar»)."""
|
|
6821
6841
|
if clean_global is not None:
|
|
6822
6842
|
current["globalMcpPolicy"] = clean_global
|
|
6823
6843
|
if clean_rules is not None:
|
|
6824
|
-
if clean_rules:
|
|
6825
|
-
current["directoryRules"][project] = clean_rules
|
|
6826
|
-
else:
|
|
6844
|
+
if clean_rules == [default_rule]:
|
|
6827
6845
|
current["directoryRules"].pop(project, None)
|
|
6846
|
+
else:
|
|
6847
|
+
current["directoryRules"][project] = clean_rules
|
|
6828
6848
|
if added_rules:
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
current["directoryRules"][project] = merged
|
|
6849
|
+
base_rules = current["directoryRules"][project] if project in current["directoryRules"] else [default_rule]
|
|
6850
|
+
current["directoryRules"][project] = self._append_rules(base_rules, added_rules)
|
|
6832
6851
|
if clean_tools is not None:
|
|
6833
6852
|
current["tools"] = self._apply_entry_patch(current.get("tools"), clean_tools)
|
|
6834
6853
|
if clean_servers is not None:
|
|
@@ -6873,7 +6892,7 @@ class AccessController:
|
|
|
6873
6892
|
Aplica una capa de políticas temporal en memoria para una ejecución en servidor, sin persistir.
|
|
6874
6893
|
De los patrones de comando solo toma los de sesión: los guardados se leen de la misma base de datos.
|
|
6875
6894
|
"""
|
|
6876
|
-
clean_global, clean_rules, clean_tools, clean_servers = self._validate_state_payload(state, SCOPE_SESSION
|
|
6895
|
+
clean_global, clean_rules, clean_tools, clean_servers = self._validate_state_payload(state, SCOPE_SESSION)
|
|
6877
6896
|
raw_patterns = state.get("commandPatterns")
|
|
6878
6897
|
session_patterns = self._limit_patterns(clean_pattern_list(raw_patterns.get("session") or [], "commandPatterns.session")) \
|
|
6879
6898
|
if isinstance(raw_patterns, dict) else None
|
|
@@ -6900,14 +6919,16 @@ class AccessController:
|
|
|
6900
6919
|
@staticmethod
|
|
6901
6920
|
def get_default_directory_rule(context: SecurityContext) -> str:
|
|
6902
6921
|
base = normalize_directory_path(str(context.workspace_dir))
|
|
6903
|
-
return f"
|
|
6922
|
+
return f"RWX:{base}" if base == "/" else f"RWX:{base}/**"
|
|
6904
6923
|
|
|
6905
6924
|
@staticmethod
|
|
6906
6925
|
def _resolve_rule_pattern(pattern: str, workspace_dir: Path | None = None) -> str:
|
|
6907
6926
|
base, sep, rest = pattern.partition("*")
|
|
6908
6927
|
if base:
|
|
6909
6928
|
# Mismo resolutor que SecurityContext.resolve_path (destino y base de la regla).
|
|
6910
|
-
target = Path(base)
|
|
6929
|
+
target = Path(base)
|
|
6930
|
+
if workspace_dir and not target.is_absolute():
|
|
6931
|
+
target = Path(workspace_dir) / target
|
|
6911
6932
|
real_base = normalize_directory_path(str(target.resolve(strict=False)))
|
|
6912
6933
|
if sep and base.endswith("/") and not real_base.endswith("/"):
|
|
6913
6934
|
real_base += "/"
|
|
@@ -6924,28 +6945,18 @@ class AccessController:
|
|
|
6924
6945
|
if not normalized_dest:
|
|
6925
6946
|
return {"allowed": False, "rule": None, "path": ""}
|
|
6926
6947
|
|
|
6927
|
-
|
|
6948
|
+
full_rule = self._full_directory_access_rule(user_rules, access)
|
|
6949
|
+
if full_rule:
|
|
6950
|
+
return {"allowed": True, "rule": full_rule, "path": normalized_dest}
|
|
6951
|
+
|
|
6928
6952
|
for raw_rule in user_rules:
|
|
6929
6953
|
parsed = parse_directory_rule(raw_rule)
|
|
6930
6954
|
if not parsed:
|
|
6931
6955
|
continue
|
|
6932
6956
|
rule_pattern = self._resolve_rule_pattern(parsed["path"], ctx.workspace_dir)
|
|
6933
|
-
if matches_directory_pattern(normalized_dest, rule_pattern):
|
|
6934
|
-
matching_user_rules.append(parsed)
|
|
6935
|
-
|
|
6936
|
-
for parsed in matching_user_rules:
|
|
6937
|
-
if parsed["access"] == access or parsed["access"] == "RW":
|
|
6957
|
+
if matches_directory_pattern(normalized_dest, rule_pattern) and all(ch in parsed["access"] for ch in access):
|
|
6938
6958
|
return {"allowed": True, "rule": parsed["rule"], "path": normalized_dest}
|
|
6939
6959
|
|
|
6940
|
-
if matching_user_rules:
|
|
6941
|
-
return {"allowed": False, "rule": None, "path": normalized_dest}
|
|
6942
|
-
|
|
6943
|
-
default_rule = self.get_default_directory_rule(ctx)
|
|
6944
|
-
default_parsed = parse_directory_rule(default_rule)
|
|
6945
|
-
if default_parsed and (default_parsed["access"] == access or default_parsed["access"] == "RW"):
|
|
6946
|
-
rule_pattern = self._resolve_rule_pattern(default_parsed["path"], ctx.workspace_dir)
|
|
6947
|
-
if matches_directory_pattern(normalized_dest, rule_pattern):
|
|
6948
|
-
return {"allowed": True, "rule": default_parsed["rule"], "path": normalized_dest}
|
|
6949
6960
|
return {"allowed": False, "rule": None, "path": normalized_dest}
|
|
6950
6961
|
|
|
6951
6962
|
def clear_session(self):
|
|
@@ -6975,7 +6986,7 @@ class AccessController:
|
|
|
6975
6986
|
if not isinstance(dec_type, str) or dec_type not in AUTHORIZE_DECISIONS or dec_type == "allow_once":
|
|
6976
6987
|
return
|
|
6977
6988
|
pattern = normalize_command_pattern(raw_pattern) if (raw_pattern and tool_name == COMMAND_TOOL) else None
|
|
6978
|
-
rules = self._validate_directory_rules([raw_dir_rule]
|
|
6989
|
+
rules = self._validate_directory_rules([raw_dir_rule]) if raw_dir_rule else []
|
|
6979
6990
|
challenge = {
|
|
6980
6991
|
"toolName": tool_name,
|
|
6981
6992
|
"serverName": server_id or "mcp-proxy",
|
|
@@ -7030,7 +7041,7 @@ class AccessController:
|
|
|
7030
7041
|
if decision == "allow_server_always" and not challenge.get("serverId"):
|
|
7031
7042
|
return None
|
|
7032
7043
|
pattern = self._validate_command_pattern(decision, command_pattern, challenge)
|
|
7033
|
-
rules = self._validate_directory_rules([directory_rule]
|
|
7044
|
+
rules = self._validate_directory_rules([directory_rule]) if directory_rule else []
|
|
7034
7045
|
challenges.pop(challenge_id)
|
|
7035
7046
|
self._record_decision(challenge, decision, pattern, rules, context)
|
|
7036
7047
|
return challenge
|
|
@@ -7074,9 +7085,12 @@ class AccessController:
|
|
|
7074
7085
|
def mutator(state: dict) -> dict:
|
|
7075
7086
|
self._store_decision(state, decision, pattern, project, tool, server_name, server_id)
|
|
7076
7087
|
if rules:
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
state["directoryRules"]
|
|
7088
|
+
base_rules = (
|
|
7089
|
+
state["directoryRules"][project]
|
|
7090
|
+
if project in state["directoryRules"]
|
|
7091
|
+
else [self.get_default_directory_rule(context)]
|
|
7092
|
+
)
|
|
7093
|
+
state["directoryRules"][project] = self._append_rules(base_rules, rules)
|
|
7080
7094
|
self._check_entry_limit(state)
|
|
7081
7095
|
return state
|
|
7082
7096
|
self._update_permanent(mutator)
|
|
@@ -7162,14 +7176,18 @@ class AccessController:
|
|
|
7162
7176
|
return POLICY_ASK, "mcp_default_ask", "", None
|
|
7163
7177
|
|
|
7164
7178
|
@staticmethod
|
|
7165
|
-
def
|
|
7166
|
-
"""
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
and parsed["access"]
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7179
|
+
def _full_directory_access_rule(rules: list[str], access: str = "RWX") -> str | None:
|
|
7180
|
+
"""Primera regla sobre la raíz (/** o /) que cubre `access`, o None."""
|
|
7181
|
+
for raw in rules:
|
|
7182
|
+
parsed = parse_directory_rule(raw)
|
|
7183
|
+
if parsed is not None and all(ch in parsed["access"] for ch in access) and parsed["path"] in ("/**", "/"):
|
|
7184
|
+
return parsed["rule"]
|
|
7185
|
+
return None
|
|
7186
|
+
|
|
7187
|
+
@classmethod
|
|
7188
|
+
def _has_full_directory_access(cls, rules: list[str]) -> bool:
|
|
7189
|
+
"""Indica si el proyecto tiene acceso RWX a todo el sistema de ficheros (RWX:/** o RWX:/)."""
|
|
7190
|
+
return cls._full_directory_access_rule(rules, "RWX") is not None
|
|
7173
7191
|
|
|
7174
7192
|
@staticmethod
|
|
7175
7193
|
def _command_target(cwd: Path, raw_path: str) -> str:
|
|
@@ -7187,14 +7205,18 @@ class AccessController:
|
|
|
7187
7205
|
|
|
7188
7206
|
def _evaluate_command(self, raw_command: str, view: dict, ctx: SecurityContext) -> tuple[str, str, str, dict | None]:
|
|
7189
7207
|
"""
|
|
7190
|
-
Valida cada subcomando por separado:
|
|
7191
|
-
|
|
7192
|
-
por un patrón o, con Workspace Trust, quedarse en el proyecto o en
|
|
7193
|
-
tubería, solo un filtro). Con
|
|
7208
|
+
Valida cada subcomando por separado: la carpeta donde se ejecuta (inicial y tras cada cd) requiere
|
|
7209
|
+
permiso X en directoryRules; cada cd debe llevar a una carpeta cubierta por las reglas de directorio,
|
|
7210
|
+
y el resto tiene que estar cubierto por un patrón o, con Workspace Trust, quedarse en el proyecto o en
|
|
7211
|
+
reglas RW del proyecto (tras una tubería, solo un filtro). Con RWX:/** en Workspace Trust, el proyecto
|
|
7212
|
+
queda sin restricción de comandos.
|
|
7194
7213
|
"""
|
|
7195
7214
|
trust = view["globalMcpPolicy"] == GLOBAL_POLICY_WORKSPACE_TRUST
|
|
7196
7215
|
if trust and self._has_full_directory_access(view["directoryRules"]):
|
|
7197
7216
|
return POLICY_ALLOW, "directory_rule_allow", "", None
|
|
7217
|
+
if not self.evaluate_directory_rule("X", str(ctx.workspace_dir), view["directoryRules"], ctx)["allowed"]:
|
|
7218
|
+
return (POLICY_ASK, "command_directory_without_execute",
|
|
7219
|
+
f"La carpeta no tiene permiso de ejecución (X): {ctx.workspace_dir}", None)
|
|
7198
7220
|
segments = split_command(raw_command)
|
|
7199
7221
|
if segments is None:
|
|
7200
7222
|
return (POLICY_ASK, "command_chaining_requires_approval",
|
|
@@ -7205,10 +7227,13 @@ class AccessController:
|
|
|
7205
7227
|
directory = cd_target(segment)
|
|
7206
7228
|
if directory is not None:
|
|
7207
7229
|
target = self._command_target(cwd, directory)
|
|
7208
|
-
if not any(self.evaluate_directory_rule(a, target, view["directoryRules"], ctx)["allowed"] for a in ("R", "W")):
|
|
7230
|
+
if not any(self.evaluate_directory_rule(a, target, view["directoryRules"], ctx)["allowed"] for a in ("R", "W", "X")):
|
|
7209
7231
|
return (POLICY_ASK, "command_directory_outside_rules",
|
|
7210
7232
|
f"El comando se ejecuta fuera de las reglas de directorio: {directory}", None)
|
|
7211
7233
|
cwd = ctx.resolve_path(target) or cwd
|
|
7234
|
+
if not self.evaluate_directory_rule("X", str(cwd), view["directoryRules"], ctx)["allowed"]:
|
|
7235
|
+
return (POLICY_ASK, "command_directory_without_execute",
|
|
7236
|
+
f"La carpeta no tiene permiso de ejecución (X): {cwd}", None)
|
|
7212
7237
|
elif any(matches_command_pattern(segment, p) for p in patterns):
|
|
7213
7238
|
continue
|
|
7214
7239
|
elif trust and self._is_allowed_trust_segment(segment, cwd, view["directoryRules"], ctx) and (
|
|
@@ -7225,12 +7250,10 @@ class AccessController:
|
|
|
7225
7250
|
return POLICY_ASK, reason, details, command_rule_offer(uncovered)
|
|
7226
7251
|
|
|
7227
7252
|
def _evaluate_path(self, tool_name: str, access: str, path: str, view: dict, ctx: SecurityContext) -> tuple[str, str, str, dict | None]:
|
|
7228
|
-
"""Herramientas integradas de ficheros: reglas de directorio
|
|
7253
|
+
"""Herramientas integradas de ficheros: reglas de directorio del proyecto."""
|
|
7229
7254
|
dir_eval = self.evaluate_directory_rule(access, path, view["directoryRules"], ctx)
|
|
7230
7255
|
if dir_eval["allowed"]:
|
|
7231
7256
|
return POLICY_ALLOW, "directory_rule_allow", "", None
|
|
7232
|
-
if view["globalMcpPolicy"] == GLOBAL_POLICY_WORKSPACE_TRUST and ctx.is_inside_workspace(path):
|
|
7233
|
-
return POLICY_ALLOW, "workspace_trust_allow", "", None
|
|
7234
7257
|
return (POLICY_ASK, "directory_rule_required", f"La ruta no coincide con una regla {access}: {path}",
|
|
7235
7258
|
directory_rule_offer(tool_name, access, dir_eval["path"] or path))
|
|
7236
7259
|
|
|
@@ -7321,7 +7344,8 @@ def live_state(ctx: SecurityContext, focus_conversation_id: str | None = None) -
|
|
|
7321
7344
|
"servers": GLOBAL_MCP_MANAGER.list_servers(),
|
|
7322
7345
|
"externalTools": GLOBAL_MCP_MANAGER.tools(),
|
|
7323
7346
|
"runs": runs,
|
|
7324
|
-
"focus_run": focus_run
|
|
7347
|
+
"focus_run": focus_run,
|
|
7348
|
+
"conversations_rev": conversations_revision()
|
|
7325
7349
|
}
|
|
7326
7350
|
|
|
7327
7351
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|