Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/features/device-proxy/device-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ async function requestDevices({
filter,
],
},
$orderby: { id: 'asc' },
},
})) as Array<Pick<Device, 'id'>>
).map(({ id }) => id);
Expand All @@ -214,18 +215,18 @@ async function requestDevices({
// Check for device update permission, except for
// internal operation of the platform.
if (method !== 'GET' && req !== permissions.root) {
await Promise.all(
deviceIds.map(async (deviceId) => {
const res = (await resinApi.post({
url: `device(${deviceId})/canAccess`,
body: { action: 'update' },
})) as { d?: Array<{ id: number }> };

if (res?.d?.[0]?.id !== deviceId) {
throw new errors.ForbiddenError();
}
}),
);
console.log('*** device-proxy');
// npm run fasttest 20 to test this
const res = (await resinApi.post({
url: `device(action='update')/canAccess?$filter=id in (${deviceIds.join(
',',
)})`,
body: {},
})) as { d?: Array<{ id: number }> };
console.log('*** device-proxy', { res: res?.d?.[0], deviceIds });
if (_.isEqual(res?.d?.[0], deviceIds)) {
throw new errors.ForbiddenError();
}
}
// And now fetch device data with full privs
return await api.resin.get({
Expand Down