From 9afe1784bd61420e47e8ce6150d7c0d817b974ba Mon Sep 17 00:00:00 2001
From: aaronagent <1115117931@qq.com>
Date: Fri, 10 Apr 2026 11:49:35 +0800
Subject: [PATCH] fix: hidden_div regex bypass with newlines, credential config
silent failure, webhook route error severity
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
prompt_builder.py: The `hidden_div` detection pattern uses `.*` which does not
match newlines in Python regex (re.DOTALL is not passed). An attacker can bypass
detection by splitting the style attribute across lines:
`
injected content
`
Replace `.*` with `[\s\S]*?` to match across line boundaries.
credential_files.py: `_load_config_files()` catches all exceptions at DEBUG level
(line 171), making YAML parse failures invisible in production logs. Users whose
credential files silently fail to mount into sandboxes have no diagnostic clue.
Promote to WARNING to match the severity pattern used by the path validation
warnings at lines 150 and 158 in the same function.
webhook.py: `_reload_dynamic_routes()` logs JSON parse failures at WARNING (line
265) but the impact — stale/corrupted dynamic routes persisting silently — warrants
ERROR level to ensure operator visibility in alerting pipelines.
Co-Authored-By: Claude Sonnet 4.6 (1M context)
---
agent/prompt_builder.py | 2 +-
gateway/platforms/webhook.py | 2 +-
tools/credential_files.py | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py
index 8302973aa..7a2086007 100644
--- a/agent/prompt_builder.py
+++ b/agent/prompt_builder.py
@@ -40,7 +40,7 @@ _CONTEXT_THREAT_PATTERNS = [
(r'disregard\s+(your|all|any)\s+(instructions|rules|guidelines)', "disregard_rules"),
(r'act\s+as\s+(if|though)\s+you\s+(have\s+no|don\'t\s+have)\s+(restrictions|limits|rules)', "bypass_restrictions"),
(r'', "html_comment_injection"),
- (r'<\s*div\s+style\s*=\s*["\'].*display\s*:\s*none', "hidden_div"),
+ (r'<\s*div\s+style\s*=\s*["\'][\s\S]*?display\s*:\s*none', "hidden_div"),
(r'translate\s+.*\s+into\s+.*\s+and\s+(execute|run|eval)', "translate_execute"),
(r'curl\s+[^\n]*\$\{?\w*(KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|API)', "exfil_curl"),
(r'cat\s+[^\n]*(\.env|credentials|\.netrc|\.pgpass)', "read_secrets"),
diff --git a/gateway/platforms/webhook.py b/gateway/platforms/webhook.py
index 6d4885d2b..9780a14d8 100644
--- a/gateway/platforms/webhook.py
+++ b/gateway/platforms/webhook.py
@@ -262,7 +262,7 @@ class WebhookAdapter(BasePlatformAdapter):
", ".join(self._dynamic_routes.keys()) or "(none)",
)
except Exception as e:
- logger.warning("[webhook] Failed to reload dynamic routes: %s", e)
+ logger.error("[webhook] Failed to reload dynamic routes: %s", e)
async def _handle_webhook(self, request: "web.Request") -> "web.Response":
"""POST /webhooks/{route_name} — receive and process a webhook event."""
diff --git a/tools/credential_files.py b/tools/credential_files.py
index 3092b75e9..b12c606cc 100644
--- a/tools/credential_files.py
+++ b/tools/credential_files.py
@@ -168,7 +168,7 @@ def _load_config_files() -> List[Dict[str, str]]:
"container_path": container_path,
})
except Exception as e:
- logger.debug("Could not read terminal.credential_files from config: %s", e)
+ logger.warning("Could not read terminal.credential_files from config: %s", e)
_config_files = result
return _config_files