{"record":{"id":"4202bc1068b9a96f","repo":"jeecgboot/JeecgBoot","slug":"error-4202bc","errorCode":null,"errorMessage":"命令参数包含非法字符，已拒绝执行: ","messagePattern":"命令参数包含非法字符，已拒绝执行: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/CommandExecUtil.java","lineNumber":56,"sourceCode":"     */\n    private static final Pattern SHELL_INJECTION_PATTERN =\n            Pattern.compile(\"[&|;<>`$!\\\\\\\\\\\\r\\\\n]\");\n\n    /**\n     * 禁止文件名中出现的危险字符（防止通过文件名注入命令）\n     */\n    private static final Pattern FILENAME_INJECTION_PATTERN =\n            Pattern.compile(\"[&|;<>`$!\\\"'\\\\r\\\\n]\");\n\n    /**\n     * 校验单个命令参数，拒绝包含 Shell 注入字符的参数\n     *\n     * @param arg 待校验参数\n     * @throws IllegalArgumentException 若参数包含危险字符\n     */\n    public static void validateArg(String arg) {\n        if (arg != null && SHELL_INJECTION_PATTERN.matcher(arg).find()) {\n            throw new IllegalArgumentException(\"命令参数包含非法字符，已拒绝执行: \" + arg);\n        }\n    }\n\n    /**\n     * 校验文件路径，拒绝包含危险字符（防止文件名注入）\n     *\n     * @param filePath 待校验文件路径\n     * @throws IllegalArgumentException 若文件路径包含危险字符\n     */\n    public static void validateFilePath(String filePath) {\n        if (filePath != null && FILENAME_INJECTION_PATTERN.matcher(filePath).find()) {\n            throw new IllegalArgumentException(\"文件路径包含非法字符，已拒绝处理: \" + filePath);\n        }\n    }\n\n    /**\n     * 执行命令行\n     *","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/CommandExecUtil.java#L38-L74","documentation":"Thrown by CommandExecUtil.validateArg(String) when a command argument contains shell metacharacters matched by SHELL_INJECTION_PATTERN: & | ; < > ` $ ! \\ \\r \\n. This is a security guard against command injection — even though execCommand uses ProcessBuilder/Runtime.exec (which bypasses the shell), the check defends against arguments that could be re-interpreted if the command vector ever changes.","triggerScenarios":"Passing any arg containing an ampersand, pipe, semicolon, backtick, dollar sign, exclamation mark, backslash, or CR/LF to execCommand(String[], String[]). For example: a filename like \"report&del.txt\", a path with \"$HOME\", or a Windows directory containing '&' in its name.","commonSituations":"User uploads a file whose name contains a restricted character (e.g. \"plan & budget.pdf\"); a URL-derived path includes a query string with '&param=value'; Windows paths containing backslashes trigger the backslash clause.","solutions":["Sanitize or rename the input argument to remove shell metacharacters before passing it to execCommand.","If the argument is a file path, strip or URL-decode query parameters and colons from the path before use.","For Windows backslashes in paths, pass the path through validateFilePath instead (which does not block backslash), or normalize to forward slashes."],"exampleFix":"// before\nString[] args = {\"-p\", fileName}; // fileName = \"report & budget.pdf\"\nCommandExecUtil.execCommand(command, args);\n\n// after\nString safeName = fileName.replaceAll(\"[&|;<>`$!\\\\\\r\\n]\", \"_\");\nString[] args = {\"-p\", safeName};\nCommandExecUtil.execCommand(command, args);","handlingStrategy":"validation","validationCode":"String safeArg = arg == null ? null : arg.replaceAll(\"[&|;<>`$!\\\\\\\\\\r\\n]\", \"_\");\n// then pass safeArg to execCommand","typeGuard":"private static boolean isSafeArg(String arg) {\n    return arg == null || !Pattern.compile(\"[&|;<>`$!\\\\\\\\\\r\\n]\").matcher(arg).find();\n}","tryCatchPattern":"try {\n    CommandExecUtil.execCommand(command, args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"命令参数包含非法字符\")) {\n        log.warn(\"Rejected arg with shell metacharacters: {}\", e.getMessage());\n        // sanitize and retry, or report to user\n    }\n    throw e;\n}","preventionTips":["Sanitize all user-derived strings before using them as command arguments.","Prefer passing structured data (file IDs) and resolve paths server-side rather than passing raw user strings.","For file paths on Windows, be aware backslash triggers this check — use validateFilePath for paths instead."],"tags":["security","command-injection","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}