fix: preserve model state, isolate commands and harden local HTTP in 1.12.1
This commit is contained in:
+8
-2
@@ -67,6 +67,11 @@ function allowRequest(request, url) {
|
||||
}
|
||||
return async (request, response) => {
|
||||
try {
|
||||
response.setHeader('Referrer-Policy', 'no-referrer');
|
||||
response.setHeader('X-Frame-Options', 'DENY');
|
||||
// Scripts and API requests belong to this workbench origin. Inline styles
|
||||
// are limited to the existing React layout; model text never becomes HTML.
|
||||
response.setHeader('Content-Security-Policy', "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'");
|
||||
const actualPort = getPort();
|
||||
if (server && (!server.listening || server.address().port !== actualPort)) throw new Error('本地执行宿主已经变化,请重新连接工作台。');
|
||||
const url = new URL(request.url, 'http://127.0.0.1:' + actualPort);
|
||||
@@ -562,9 +567,10 @@ return async (request, response) => {
|
||||
maxTaskTokens: Math.trunc(Math.max(1000, Math.min(10000000, Number(input.maxTaskTokens) || store.config.maxTaskTokens))),
|
||||
};
|
||||
provider.validate(config);
|
||||
if (Object.hasOwn(input, 'apiKey') && (typeof input.apiKey !== 'string' || input.apiKey.length > 16000)) throw new Error('模型凭据格式无效。');
|
||||
if (provider.hub) provider.hub.select({ type: 'legacy' }, config);
|
||||
else store.saveConfig(config);
|
||||
if (Object.hasOwn(input, 'apiKey')) provider.setKey(input.apiKey);
|
||||
if (provider.hub) provider.hub.select({ type: 'legacy' });
|
||||
store.saveConfig(config);
|
||||
return json(response, { ...store.config, hasKey: provider.hasKey() });
|
||||
}
|
||||
if (method === 'POST' && route === '/api/config/models') {
|
||||
|
||||
Reference in New Issue
Block a user