The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(lint): stdin guard reads only real stdin settings; unbroker key generation leaves no partial file (review)
alt-glitch04dc1c6ea059
diff --git a/optional-skills/security/unbroker/scripts/crypto.py b/optional-skills/security/unbroker/scripts/crypto.pyindex 135f940226e..e479e98017a 100644--- a/optional-skills/security/unbroker/scripts/crypto.py+++ b/optional-skills/security/unbroker/scripts/crypto.py@@ -53,8 +53,16 @@ def ensure_identity() -> Path:p.parent.chmod(0o700)except OSError:pass- subprocess.run(["age-keygen", "-o", str(p)], check=True, capture_output=True,- stdin=subprocess.DEVNULL, timeout=30)+ # Generate beside the target and move it into place, so a timed-out or failed run+ # leaves no partial identity that the exists() check above would accept next time.+ partial = p.with_name(f"{p.name}.partial")+ partial.unlink(missing_ok=True)+ try:+ subprocess.run(["age-keygen", "-o", str(partial)], check=True, capture_output=True,+ stdin=subprocess.DEVNULL, timeout=30)+ partial.replace(p)+ finally:+ partial.unlink(missing_ok=True)try:p.chmod(0o600)except OSError:diff --git a/scripts/check_subprocess_stdin.py b/scripts/check_subprocess_stdin.pyindex 34e3f198363..bb07981d740 100644--- a/scripts/check_subprocess_stdin.py+++ b/scripts/check_subprocess_stdin.py@@ -103,13 +103,25 @@ def _definition_sets_stdin(tree: ast.AST, name: str) -> bool:return node is not None and _sets_stdin(node)+def _is_stdin_key(node: ast.AST | None) -> bool:+ return isinstance(node, ast.Constant) and node.value == "stdin"++def _sets_stdin(node: ast.AST) -> bool:- """stdin appears as a keyword (dict(stdin=...)) or a dict-literal key ({"stdin": ...})."""- return any(- (isinstance(sub, ast.keyword) and sub.arg == "stdin")- or (isinstance(sub, ast.Constant) and sub.value == "stdin")- for sub in ast.walk(node)- )+ """stdin is set as a keyword (``dict(stdin=...)``), a dict-literal key (``{"stdin": ...}``),+ a subscript store (``kw["stdin"] = ...``) or ``kw.setdefault("stdin", ...)``. A ``"stdin"``+ string anywhere else (a value, a path) does not count."""+ for sub in ast.walk(node):+ if isinstance(sub, ast.keyword) and sub.arg == "stdin":+ return True+ if isinstance(sub, ast.Dict) and any(_is_stdin_key(key) for key in sub.keys):+ return True+ if isinstance(sub, ast.Subscript) and isinstance(sub.ctx, ast.Store) and _is_stdin_key(sub.slice):+ return True+ if (isinstance(sub, ast.Call) and isinstance(sub.func, ast.Attribute)+ and sub.func.attr == "setdefault" and sub.args and _is_stdin_key(sub.args[0])):+ return True+ return Falsedef _is_inheriting_call(call: ast.Call) -> bool:@@ -129,12 +141,12 @@ def _call_is_safe(call: ast.Call, tree: ast.AST) -> bool:return Trueif kw.arg is not None:continue+ # Inline splat that sets it: ``**dict(stdin=...)`` / ``**{"stdin": ...}``.+ if _sets_stdin(kw.value):+ return True# ``**name`` / ``**name(...)`` splat: safe when the same-file definition sets stdin=.value = kw.value.func if isinstance(kw.value, ast.Call) else kw.value- if isinstance(value, ast.Name):- if _definition_sets_stdin(tree, value.id):- return True- elif _sets_stdin(kw.value): # inline ``**dict(stdin=...)`` / ``**{"stdin": ...}``+ if isinstance(value, ast.Name) and _definition_sets_stdin(tree, value.id):return Truereturn False