mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
Address code review feedback: improve validation patterns and escaping
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
1 parent
0a2d7b1597
commit
d20e154f21
4 files changed
+9
-147
No files matched your search
+2
-2
@@ -79,8 +79,8 @@ export default (app: Router) => {
|
||||
{ pattern: /(curl|wget)[^;]*\|\s*bash/gi, desc: '下载并直接执行的危险模式' },
|
||||
{ pattern: /(curl|wget)[^;]*&&\s*chmod\s*\+x/gi, desc: '下载并赋予执行权限的可疑模式' },
|
||||
|
||||
// External URLs downloading executables with suspicious names
|
||||
{ pattern: /https?:\/\/[^\s]+\/(fullgc|\.[\w-]+)[\s;"']/gi, desc: '可疑的外部可执行文件下载' },
|
||||
// Downloads of hidden files (commonly used in malware)
|
||||
{ pattern: /(curl|wget)[^|;]*https?:\/\/[^\s]+\/\.\w+/gi, desc: '可疑的隐藏文件下载' },
|
||||
|
||||
// Background execution of hidden files
|
||||
{ pattern: /nohup\s+["']?[^"'\s]*\/\.\w+["']?\s*>/gi, desc: '后台执行隐藏文件' },
|
||||
|
||||
@@ -646,8 +646,9 @@ export default class CronService {
|
||||
private escapeShellArg(arg: string): string {
|
||||
if (!arg) return "''";
|
||||
|
||||
// Remove newlines and normalize whitespace
|
||||
arg = arg.replace(/\r?\n/g, ';').trim();
|
||||
// Remove newlines to prevent creating command chains
|
||||
// Replace with space to maintain token separation
|
||||
arg = arg.replace(/\r?\n/g, ' ').trim();
|
||||
|
||||
// Use single quotes and escape any single quotes within
|
||||
// This is the most secure way to pass arbitrary strings to shell
|
||||
|
||||
@@ -28,14 +28,14 @@ const validateShellSecurity = (value: any, helpers: any, fieldName: string): any
|
||||
// Background process spawning with suspicious names
|
||||
/nohup\s+["']?[^\s"']*\/\.\w+/,
|
||||
|
||||
// Redirect to dev null (hiding output) combined with background execution
|
||||
/>.*\/dev\/null.*&/,
|
||||
// Redirect to dev null combined with downloads (hiding malware output)
|
||||
/(curl|wget|fetch)[^;]*>.*\/dev\/null.*&/i,
|
||||
|
||||
// Base64 decode patterns (often used to obfuscate malicious code)
|
||||
/\b(base64|decode|eval)\s+/i,
|
||||
|
||||
// File execution from temp directory
|
||||
/\b\/tmp\/[^\s]+/,
|
||||
// Executable files in /tmp with chmod or execution
|
||||
/\/tmp\/[^\s]+\s*(&&|;)\s*(chmod|\.\/)/ ,
|
||||
];
|
||||
|
||||
for (const pattern of dangerousPatterns) {
|
||||
|
||||
Reference in new issue
Block a user