mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
fix(security): restrict task environment controls and app scopes
This commit is contained in:
1 parent
a5f22f8d44
commit
b0f15241d2
17 files changed
+364
-30
No files matched your search
+24
-1
@@ -112,7 +112,30 @@ export default ({ app }: { app: Application }) => {
|
||||
const keyMatch = pathLower.match(/\/open\/([a-z]+)\/*/);
|
||||
const key = keyMatch && keyMatch[1];
|
||||
|
||||
if (!doc.scopes.includes(key as AppScope)) {
|
||||
const hasNamespaceScope =
|
||||
doc.scopes.includes(key as AppScope) ||
|
||||
(key === 'envs' && doc.scopes.includes('envs:write'));
|
||||
if (!hasNamespaceScope) {
|
||||
const err = new UnauthorizedError('credentials_bad_scheme', {
|
||||
message: t('暂无权限'),
|
||||
});
|
||||
return next(err);
|
||||
}
|
||||
|
||||
// Config files can contain task hooks and shell code. External app
|
||||
// tokens may read them, but only panel credentials may write them.
|
||||
// The built-in system app still needs its local CLI maintenance API.
|
||||
const appRouteAllowed =
|
||||
(key !== 'envs' ||
|
||||
['GET', 'HEAD'].includes(req.method) ||
|
||||
doc.scopes.includes('envs:write')) &&
|
||||
(key !== 'configs' || ['GET', 'HEAD'].includes(req.method)) &&
|
||||
(key !== 'system' ||
|
||||
doc.name === 'system' ||
|
||||
((req.method === 'GET' || req.method === 'HEAD') &&
|
||||
(pathLower === '/open/system' || pathLower === '/open/system/')) ||
|
||||
(req.method === 'PUT' && pathLower === '/open/system/notify'));
|
||||
if (!appRouteAllowed) {
|
||||
const err = new UnauthorizedError('credentials_bad_scheme', {
|
||||
message: t('暂无权限'),
|
||||
});
|
||||
|
||||
@@ -222,6 +222,9 @@ export default async () => {
|
||||
}
|
||||
} catch { }
|
||||
|
||||
// Replace legacy task environment files before recovered tasks can run.
|
||||
await envService.set_envs();
|
||||
|
||||
// 初始化保存一次ck和定时任务数据
|
||||
cronClient.readiness.configure(async () => {
|
||||
await cronService.autosave_crontab(true);
|
||||
@@ -229,8 +232,6 @@ export default async () => {
|
||||
});
|
||||
await cronClient.readiness.recover();
|
||||
|
||||
await envService.set_envs();
|
||||
|
||||
const authInfo = await userService.getAuthInfo();
|
||||
await shareStore.updateAuthInfo(authInfo);
|
||||
await openService.refreshApps();
|
||||
|
||||
Reference in new issue
Block a user