mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
fix: close remaining security advisory paths
This commit is contained in:
1 parent
ebe1a3644b
commit
4b3c31c0a7
5 files changed
+55
-12
No files matched your search
@@ -10,7 +10,16 @@ import ConfigService from '../services/config';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
import { resolveFileAccess } from '../shared/fileAccess';
|
||||
import { rateLimit } from 'express-rate-limit';
|
||||
import path from 'path';
|
||||
const route = Router();
|
||||
const openApiProtectedFiles = new Set([
|
||||
'config.sh',
|
||||
'task_before.sh',
|
||||
'task_after.sh',
|
||||
'task_before.js',
|
||||
'task_before.py',
|
||||
'extra.sh',
|
||||
]);
|
||||
|
||||
export default (app: Router) => {
|
||||
app.use('/configs', route);
|
||||
@@ -85,6 +94,16 @@ export default (app: Router) => {
|
||||
if (!normalized) {
|
||||
return res.send({ code: 403, message: t('文件无法访问') });
|
||||
}
|
||||
// OpenAPI config scopes grant data-file access, not executable hooks.
|
||||
if (/(?:^|\/)open\/configs(?:\/|\?|$)/.test(req.originalUrl || '')) {
|
||||
const realPath = await fs.realpath(normalized).catch(() => normalized);
|
||||
if (
|
||||
openApiProtectedFiles.has(path.basename(normalized).toLowerCase()) ||
|
||||
openApiProtectedFiles.has(path.basename(realPath).toLowerCase())
|
||||
) {
|
||||
return res.send({ code: 403, message: t('文件无法访问') });
|
||||
}
|
||||
}
|
||||
await writeFileWithLock(normalized, content);
|
||||
res.send({ code: 200, message: t('保存成功') });
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user