fix(security): decode settings at the API boundary and honour the transaction
Round-three review follow-ups. getImageSecurityDefaults now accepts a transaction, the way getAppSetting two lines above it already does. quoteService.convertToEvent called it from inside db.transaction() through the global db; sqlite3 runs a single-connection pool, so that read would have waited on the connection its own transaction was holding until the acquire timeout, and the helper's catch would then have swallowed the error and dropped the defaults silently. The double-encoding is fixed where it starts. GET /admin/image-security/settings returned setting_value undecoded, so it shipped "true" to a tab that types the field as boolean — and since the tab PUTs the whole object back through JSON.stringify, every save wrapped another layer around values nobody edited. It decodes now, so a round trip is idempotent. The tab is the only consumer of that endpoint. The reader unwraps to any depth instead of four. The depth on an existing install is however many times someone opened that tab, which is not a number to cap. It terminates because each parse of a string is strictly shorter than its input. Refs #1296
This commit is contained in:
@@ -134,6 +134,15 @@ describe('image-security creation defaults', () => {
|
||||
expect(await getImageSecurityDefaults()).toEqual({ image_quality: 72 });
|
||||
});
|
||||
|
||||
it('reads a value buried under many saves, not just one', async () => {
|
||||
// Each visit to the settings tab used to add a layer, so the depth is
|
||||
// however many times someone opened it — not a number to cap.
|
||||
let raw = JSON.stringify('maximum');
|
||||
for (let i = 0; i < 8; i += 1) raw = JSON.stringify(raw);
|
||||
await setRaw('default_protection_level', raw);
|
||||
expect(await getImageSecurityDefaults()).toEqual({ protection_level: 'maximum' });
|
||||
});
|
||||
|
||||
it('still rejects a malformed value however many times it was encoded', async () => {
|
||||
await setRaw('default_image_quality', JSON.stringify(JSON.stringify('72oops')));
|
||||
expect(await getImageSecurityDefaults()).toEqual({});
|
||||
|
||||
Reference in New Issue
Block a user