fix(realm): revalidate settings sessions before acquiring a transaction connection

This commit is contained in:
unimatrix 2026-11-17 20:01:24 +00:00
commit c0c2e8b35e

View file

@ -15,8 +15,9 @@ export function createOrganisationSettingsRoute(db,{origin='https://cp.dunerealm
if(request.method==='POST'&&request.headers.get('origin')!==origin)return reply({message:'Request origin rejected.'},403);
try{
let input;if(request.method==='POST'){const text=await request.text();if(text.length>6000)throw failure('Settings request too large.',413);try{input=JSON.parse(text);}catch{throw failure('Invalid settings.',400);}if(!input||!['motd','identity'].includes(input.action)||!Number.isSafeInteger(input.revision)||input.revision<0)throw failure('Refresh and review the current settings.',400);}
// Revalidate before acquiring a transaction connection; authentication uses the same pool.
const fresh=await authenticate(request);if(fresh?.id!==user.id||!(await access(fresh)).nodes.includes('web.menu.game'))throw failure('Your session changed.',403);
return await db.transaction(async tx=>{
const fresh=await authenticate(request);if(fresh?.id!==user.id)throw failure('Your session changed.',403);
let organisation;
if(kind==='company'){
organisation=await tx.first("SELECT id,name,description,updated_at,founded_by,ceo_account_id FROM corrino_companies WHERE id=? AND status IN ('active','pending') FOR UPDATE",[id]);