T09 · Insecure Skill Coding Practices
Warning
- Location
- main.py:78
- Finding
- Unvalidated User Input Enables AliMail Directory Filter Manipulation## Vulnerability Details **File Location**: `main.py`, lines 78-85 **Vulnerability Type**: Filter injection through unescaped user input **Risk Level**: Medium ```python url = f"{self.base}/v2/users" params = {"filter": f"(name=*{name})", "size": 10} headers = {"Authorization": f"Bearer {token}"} try: res = requests.get(url, params=params, headers=headers, timeout=10) ``` ### Technical Analysis The externally supplied `name` argument is inserted directly into a structured AliMail filter expression: ```python f"(name=*{name})" ``` The code performs no validation or escaping of wildcard characters, parentheses, or other metacharacters recognized by the remote filter parser. Consequently, input such as a wildcard can broaden the search beyond a specific employee. Crafted delimiters may also alter the filter expression if the AliMail API accepts compound or nested filter syntax. URL encoding performed by `requests` does not prevent this issue because it only ensures safe HTTP transport; the remote API decodes the parameter before interpreting its filter syntax. ### Attack Path 1. An attacker or unauthorized caller gains access to the `search_alimail_user` Skill tool. 2. The attacker supplies a wildcard or crafted filter expression as the `name` parameter. 3. `main.py` embeds the value directly into the `filter` query parameter. 4. The request is authenticated using the configured AliMail service credential and sent to `/v2/users`. 5. The AliMail service evaluates the broadened or manipulated filter under the service account's permissions. 6. The Skill returns matching employee names, email addresses, employee numbers, and the overall match count. 7. Repeated requests may allow broader enumeration of the enterprise directory. ### Impact Assessment Successful exploitation may disclose internal employee directory information beyond the intended lookup, including names, email addresses, employee numbe ...[truncated 536 chars]
- Remediation
- ## Remediation Suggestions 1. Validate the `name` parameter against a restrictive allowlist appropriate for employee names. Reject wildcard characters, parentheses, control characters, and filter operators. 2. Escape all filter metacharacters according to the official AliMail filter grammar before constructing the expression. 3. Prefer an AliMail API parameter that accepts a literal name rather than exposing raw filter syntax, if such an endpoint is available. 4. Enforce reasonable minimum and maximum input lengths to prevent broad one-character searches and resource abuse. 5. Consider exact matching by default and expose fuzzy matching only through a controlled server-side transformation. 6. Apply authorization and rate limiting at the Skill boundary to restrict directory searches to approved users and reduce enumeration risk. 7. Return only fields required by the caller. Avoid exposing `employeeNo` or the total match count unless operationally necessary. 8. Add tests covering wildcard-only input, parentheses, logical operators, malformed filters, empty input, and unusually long values.
