Back to skill

Security audit

RegexAssistant

Security checks for vulnerabilities and agentic risk

Overview

This is a localized regex testing helper that runs a small local Python CLI and does not show hidden persistence, network access, credential handling, or destructive behavior.

Install only if Chinese-language CLI output is acceptable. Avoid running untrusted or very complex regex patterns against large text, because a catastrophic-backtracking pattern may stall the skill process until stopped.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Warning
Location
script/main.py:47
Finding
Unbounded User-Controlled Regular Expressions Enable Denial of Service<![CDATA[ ## Vulnerability Details **File Location**: `script/main.py:47`, `script/main.py:65`, `script/main.py:86`, `script/main.py:104`, `script/main.py:132-137` **Vulnerability Type**: Regular Expression Denial of Service (ReDoS) **Risk Level**: Medium ### Vulnerable Code ```python # match_test(), line 47 result = re.search(pattern, text, flags) # find_all(), line 65 matches = re.findall(pattern, text, flags) # find_iter(), line 86 for i, match in enumerate(re.finditer(pattern, text, flags), 1): # groups(), line 104 result = re.search(pattern, text, flags) # substitute(), lines 132-137 result = re.sub(pattern, replacement, text, count=count, flags=flags) print(f"替换后: {result}") # 显示替换次数 if count == 0: matches = re.findall(pattern, text, flags) ``` ### Technical Analysis The `pattern` and `text` arguments are obtained directly from unrestricted command-line input and passed to Python's backtracking `re` engine. No execution timeout, input-length limit, pattern-complexity restriction, or process-level resource boundary is applied. Certain expressions containing nested or ambiguous quantifiers can trigger catastrophic backtracking. For example, the pattern `(a+)+$` applied to a long string of `a` characters followed by a nonmatching character may require exponentially increasing evaluation time. The existing `except re.error` handlers only handle invalid regular-expression syntax. They do not interrupt a syntactically valid expression that consumes excessive CPU. All matching operations are affected, including search, extraction, iteration, grouping, and substitution. ### Attack Path 1. An attacker or untrusted caller invokes a command that accepts an arbitrary regular expression, such as `match`. 2. The caller supplies a backtracking-intensive pattern such as `(a+)+$`. 3. The caller supplies a sufficiently long near-matching string consisting of repeated `a` characters followed by a nonmatching character. 4. `argparse` passes both values uncha ...[truncated 818 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Execute every untrusted regular-expression operation in a separate worker process with a strict wall-clock timeout. Terminate the worker if the deadline is exceeded. 2. Do not rely solely on a thread-based timeout because a long-running native regular-expression operation may prevent timely interruption. 3. Enforce conservative maximum lengths for both patterns and input text before evaluation. 4. Consider replacing Python's backtracking engine with a linear-time regular-expression engine when the required syntax is supported. 5. Reject or warn about high-risk constructs such as nested quantifiers and ambiguous repeated groups. Treat this as defense in depth rather than a complete ReDoS detector. 6. Apply memory and CPU limits to worker processes where the operating environment supports them. 7. Return a controlled timeout error without echoing unnecessarily large attacker-provided inputs. 8. Add regression tests using known catastrophic-backtracking patterns against near-matching input to verify that execution is terminated within the configured deadline. ]]>
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
Findings (2)

Natural-Language Policy Violations

Medium
Confidence
93% confidence
Finding
The skill metadata and main description are written entirely in Chinese, and the examples/pattern catalog are tailored to Chinese-specific data formats such as mainland China phone numbers and ID cards. There is no statement that users may choose another language or that the locale limitation is intentional and justified, which creates a language/locale policy concern.

Natural-Language Policy Violations

Low
Confidence
91% confidence
Finding
The file’s natural-language description and all user-facing CLI messages are written in Chinese, and the predefined patterns/descriptions are specifically oriented to Chinese-language usage. There is no indication that users can choose another language or locale, which may violate a language-choice policy when such choice is expected.

Static analysis

No suspicious patterns detected.