Enforce claim permission and bounded full USB enrollment envelopes
Device Core qualification / qualify (push) Successful in 8m31s

This commit is contained in:
DCCONSTRUCTIONS
2026-10-01 09:33:04 +03:00
parent dc9fe6e0fc
commit be30fafa95
6 changed files with 32 additions and 3 deletions
+1 -1
View File
@@ -211,7 +211,7 @@ export function createControlCoreApp({
const requestId = String(request.headers["idempotency-key"] || "");
if (!/^[a-f0-9]{32}$/.test(requestId)) throw new TypeError("b2_request_id_invalid");
const actor = managementActorFromHeaders(request.headers);
const input = await readJsonBody(request, 64 * 1024);
const input = await readJsonBody(request, 128 * 1024);
const result = await b2Infrastructure.execute(actor, input, requestId);
return writeJson(response, 200, { ok: true, result });
}
@@ -204,6 +204,7 @@ export class B2Infrastructure {
try {
await db.query('begin');
await findProjectWithCapability(db, actor, projectId, 'device.enroll');
if (request.action === 'register') await findProjectWithCapability(db, actor, projectId, 'device.claim');
source = (await db.query(`select s.* from device_b2_hosts s
join device_b2_host_views v on v.source_id=s.id
join device_b2_contour_links l on l.source_id=s.id and l.project_id=v.project_id
@@ -360,3 +360,14 @@ test('enrollment validates project capability, active host and contour before fo
await assert.rejects(denied.execute({ ...actor, hubRole: 'member' }, input));
await assert.rejects(denied.execute({ ...actor, hubRole: 'member' }, { projectRef: input.projectRef, action: 'enrollment-options' }));
});
test('enrollment permission alone cannot claim a device into a project', async () => {
const repo = repository({ role: 'engineer' }), db = await repo.pool.connect(), original = db.query;
db.query = async (sql, values) => {
const result = await original(sql, values);
if (sql.includes('from device_project_grants')) result.rows[0].capability_deny = ['device.claim'];
return result;
};
const service = new B2Infrastructure({ pool: repo.pool, secrets: { read: async () => assert.fail('no remote credentials') } });
await assert.rejects(service.execute({ ...actor, hubRole: 'member' }, { projectRef: `project:${projectId}`, hostRef: `host:${hostId}`, action: 'enrollment', contourId: 'a'.repeat(32), request: { action: 'register', imei: '323456789012345', number: 300, name: 'B2' } }));
});