fix: prevent plugin config leak to non-admin users
This commit is contained in:
@@ -51,13 +51,18 @@ export async function GET(
|
|||||||
|
|
||||||
const config = await getPluginConfig(id);
|
const config = await getPluginConfig(id);
|
||||||
|
|
||||||
let response: Record<string, unknown> = config;
|
let response: Record<string, unknown>;
|
||||||
if (!isAdmin && plugin.configSchema) {
|
if (isAdmin) {
|
||||||
|
response = config;
|
||||||
|
} else {
|
||||||
response = {};
|
response = {};
|
||||||
for (const [key, value] of Object.entries(config)) {
|
const schema = plugin.configSchema;
|
||||||
const field = plugin.configSchema[key];
|
if (schema) {
|
||||||
if (field?.type === 'secret') continue;
|
for (const [key, value] of Object.entries(config)) {
|
||||||
response[key] = value;
|
const field = schema[key];
|
||||||
|
if (!field || field.type === 'secret') continue;
|
||||||
|
response[key] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +115,13 @@ export async function PUT(
|
|||||||
return NextResponse.json({ error: 'Invalid key format' }, { status: 400 });
|
return NextResponse.json({ error: 'Invalid key format' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (plugin.configSchema && !plugin.configSchema[body.key]) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: 'Key is not declared in the plugin configSchema' },
|
||||||
|
{ status: 400 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await setPluginConfig(id, body.key, body.value);
|
await setPluginConfig(id, body.key, body.value);
|
||||||
return NextResponse.json({ ok: true });
|
return NextResponse.json({ ok: true });
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user