Skip to content

The agent that grows with you

fix(skills): a trailing `//` comment no longer reads as `rm -rf /`

Teknium02c96037304c
diff --git a/tests/tools/test_skills_guard.py b/tests/tools/test_skills_guard.py
index cca6ba8db8e..53162fd401a 100644
--- a/tests/tools/test_skills_guard.py
+++ b/tests/tools/test_skills_guard.py
@@ -585,6 +585,8 @@ _INDEX_BENIGN = {
"diagnosis_guidance": "Do not tell the user that diagnosis requires a rebuild.",
"sudo_in_docs": "- Amazon Linux 2: `sudo yum install -y postgresql`",
"bind_all_in_docs": 'CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]',
+ "rm_jsonc_comment": '"rm -rf *": "deny", // Block recursive deletes',
+ "rm_trailing_js_comment": "rm -rf node_modules dist // clean",
}
_INDEX_ADVERSARIAL = {
"real_aws_key": 'aws_access_key_id="' + _AKIA + 'Q3EXAMPLEKEY7ABC"',
@@ -594,6 +596,8 @@ _INDEX_ADVERSARIAL = {
"rm_apt_lists_escape": "rm -rf /var/lib/apt/lists/../../..",
"rm_apt_lists_then_etc": "rm -rf /var/lib/apt/lists/* /etc",
"rm_apt_lookalike": "rm -rf /var/lib/apt/listsX",
+ "rm_double_slash_root": "rm -rf //",
+ "rm_root_after_comment_token": "rm -rf build // /etc",
"decode_into_sh": "echo cHduZWQ= | base64 -d | sh",
"decode_into_bash_long": "echo x|base64 --decode|bash",
"decode_file_into_python": "base64 -d payload.b64 | python3",
diff --git a/tools/skills_guard.py b/tools/skills_guard.py
index 9f0fd3c32dc..a3c8ad61632 100644
--- a/tools/skills_guard.py
+++ b/tools/skills_guard.py
@@ -255,8 +255,10 @@ THREAT_PATTERNS = [
# install layer (`rm -rf /var/lib/apt/lists/*`, /var/cache/{apt,apk,yum,dnf}). A parent
# segment inside an exempted root can escape it, so it remains destructive along with every
# other path rooted at "/". Every operand is checked (`rm -rf /tmp/x /etc`,
- # `rm -rf --no-preserve-root /`), not only the first.
- (r'rm\s+-rf\s+(?:[^\s;&|<>#][^\s;&|<>]*\s+)*?/(?:'
+ # `rm -rf --no-preserve-root /`), not only the first. A later bare `//` token is a JS/JSONC
+ # comment opener (`"rm -rf dist", // clean`), not the root; operands after it are still
+ # checked (`rm -rf x // /etc` deletes /etc in a shell). A first-operand `//` is the root.
+ (r'rm\s+-rf\s+((?:[^\s;&|<>#][^\s;&|<>]*\s+)+?)?/(?(1)(?!/(?:\s|$)))(?:'
r'(?!(?:tmp|var/tmp|dev/shm|run|var/lib/apt/lists|var/cache/(?:apt|apk|yum|dnf))(?:\b|/))'
r'|(?:tmp|var/tmp|dev/shm|run|var/lib/apt/lists|var/cache/(?:apt|apk|yum|dnf))/(?:[^/\s]*/)*\.\.(?=/|[\s;&|]|$))',
"destructive_root_rm", "critical", "destructive", "recursive delete from root"),