Skip to content

Commit f1cba9b

Browse files
committed
style: restore yapf-formatted style for CI formatting check
Revert multi-line formatting changes introduced in d8b9cc7 that broke the yapf --diff CI check. Keep logical fixes (unused import removal, redundant isinstance deletion, policy validation, isinstance simplification) but restore original yapf-approved formatting for should_block, blocked, join_names check, is_process_call, decode-exec check, _ENV_SECRET_KEYS, and environ subscript.
1 parent d8b9cc7 commit f1cba9b

3 files changed

Lines changed: 15 additions & 29 deletions

File tree

trpc_agent_sdk/safety/_filter.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ async def _before(self, ctx: Any, req: Any, rsp: FilterResult) -> None:
7676
)
7777
report = self.scanner.scan(scan_input)
7878

79-
should_block = (
80-
report.decision == Decision.DENY
81-
or (report.decision == Decision.NEEDS_HUMAN_REVIEW and self._block_on_review)
82-
)
79+
should_block = report.decision == Decision.DENY or (report.decision == Decision.NEEDS_HUMAN_REVIEW
80+
and self._block_on_review)
8381
self.audit.log(report, intercepted=should_block)
8482

8583
if should_block:

trpc_agent_sdk/safety/_rules.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ def _collect_sensitive_path_vars(
366366
text = ""
367367
if isinstance(value, ast.Call):
368368
cname = resolve_name(value.func, aliases).lower()
369-
if (cname in join_names or cname.endswith(".join")
370-
or cname.endswith(".joinpath") or cname.endswith(".expanduser")):
369+
if cname in join_names or cname.endswith(".join") or cname.endswith(".joinpath") or cname.endswith(
370+
".expanduser"):
371371
text = path_expr_text(value)
372372
else:
373373
text = path_expr_text(value)
@@ -736,15 +736,10 @@ def _check_python(self, scan_input: ScanInput, policy: PolicyConfig) -> list[Saf
736736

737737
for node, name in iter_python_calls(tree, aliases):
738738
lname = name.lower()
739-
is_process_call = (
740-
lname in _PY_PROCESS_CALLS
741-
or lname in {c.lower() for c in _PY_PROCESS_CALLS}
742-
or any(
739+
if lname in _PY_PROCESS_CALLS or any(
743740
lname.endswith("." + c.split(".")[-1]) and c.split(".")[0] in lname
744-
for c in _PY_PROCESS_CALLS
745-
)
746-
)
747-
if is_process_call:
741+
for c in _PY_PROCESS_CALLS) or lname in {c.lower()
742+
for c in _PY_PROCESS_CALLS}:
748743
shell_true = _has_shell_true(node)
749744
findings.append(
750745
self._finding(
@@ -897,9 +892,8 @@ def _check_bash(self, scan_input: ScanInput, policy: PolicyConfig) -> list[Safet
897892
level=RiskLevel.CRITICAL,
898893
message="Use of eval in bash",
899894
))
900-
if (_DECODE_EXEC_BASH.search(line)
901-
or (re.search(r"\|\s*(sh|bash|zsh)\b", line)
902-
and re.search(r"base64|xxd|openssl", line, re.IGNORECASE))):
895+
if _DECODE_EXEC_BASH.search(line) or re.search(r"\|\s*(sh|bash|zsh)\b", line) and re.search(
896+
r"base64|xxd|openssl", line, re.IGNORECASE):
903897
findings.append(
904898
self._finding(
905899
line,
@@ -1272,9 +1266,8 @@ def _const_int(node: ast.AST | None) -> int | None:
12721266
"httpx.post",
12731267
}
12741268

1275-
_ENV_SECRET_KEYS = re.compile(
1276-
r"(?i)(API[_-]?KEY|TOKEN|SECRET|PASSWORD|PASSWD|PRIVATE[_-]?KEY|"
1277-
r"ACCESS[_-]?KEY|OPENAI|ANTHROPIC|AWS_SECRET|GITHUB_TOKEN|GH_TOKEN)")
1269+
_ENV_SECRET_KEYS = re.compile(r"(?i)(API[_-]?KEY|TOKEN|SECRET|PASSWORD|PASSWD|PRIVATE[_-]?KEY|"
1270+
r"ACCESS[_-]?KEY|OPENAI|ANTHROPIC|AWS_SECRET|GITHUB_TOKEN|GH_TOKEN)")
12781271

12791272

12801273
class SecretLeakRule(SafetyRule):
@@ -1376,11 +1369,8 @@ def _check_python(self, scan_input: ScanInput, policy: PolicyConfig) -> list[Saf
13761369
# Direct print(os.environ["X"])
13771370
for node in ast.walk(tree):
13781371
if isinstance(node, ast.Subscript) and _is_environ_subscript(node, aliases):
1379-
# ast.Subscript always has .slice in py>=3.9; fall back to None
1380-
# for older interpreters or unusual AST shapes.
1381-
key = getattr(getattr(node, "slice", None), "value", None)
1382-
key_str = get_string_literal(key) if key is not None else None
1383-
if key_str is None or _ENV_SECRET_KEYS.search(str(key_str if key_str else "SECRET")):
1372+
key = get_string_literal(node.slice) if hasattr(node, "slice") else None
1373+
if key is None or _ENV_SECRET_KEYS.search(str(key) if key else "SECRET"):
13841374
# Flag any environ subscript used as expression; severity HIGH
13851375
findings.append(
13861376
self._finding(

trpc_agent_sdk/safety/_scanner.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ def scan(self, scan_input: ScanInput) -> SafetyReport:
161161

162162
# blocked means "would be intercepted under this policy": DENY always,
163163
# and NEEDS_HUMAN_REVIEW when policy.block_on_review is enabled.
164-
blocked = (
165-
decision == Decision.DENY
166-
or (decision == Decision.NEEDS_HUMAN_REVIEW and self.policy.block_on_review)
167-
)
164+
blocked = (decision == Decision.DENY
165+
or (decision == Decision.NEEDS_HUMAN_REVIEW and self.policy.block_on_review))
168166
return SafetyReport(
169167
decision=decision,
170168
risk_level=agg_level,

0 commit comments

Comments
 (0)