Skip to content

Commit 6b4a19e

Browse files
committed
fix: implicit app permissions bug
1 parent 48fea77 commit 6b4a19e

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

src/backend/src/services/auth/PermissionService.js

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
const { get_user, get_app } = require("../../helpers");
2525
const { AssignableMethodsFeature } = require("../../traits/AssignableMethodsFeature");
2626
const { Context } = require("../../util/context");
27+
const { get_a_letter, cylog } = require("../../util/debugutil");
2728
const BaseService = require("../BaseService");
2829
const { DB_WRITE } = require("../database/consts");
2930
const { UserActorType, Actor, AppUnderUserActorType, AccessTokenActorType, SiteActorType } = require("./Actor");
@@ -220,6 +221,10 @@ class PermissionService extends BaseService {
220221
if ( ! Array.isArray(permission_options) ) {
221222
permission_options = [permission_options];
222223
}
224+
225+
// TODO: command to enable these logs
226+
// const l = get_a_letter();
227+
// cylog(l, 'ACT & PERM:', actor.uid, permission_options);
223228

224229
const start_ts = Date.now();
225230
await require('../../structured/sequence/scan-permission')
@@ -229,6 +234,10 @@ class PermissionService extends BaseService {
229234
reading,
230235
});
231236
const end_ts = Date.now();
237+
238+
// TODO: command to enable these logs
239+
// cylog(l, 'READING', JSON.stringify(reading, null, ' '));
240+
232241
reading.push({
233242
$: 'time',
234243
value: end_ts - start_ts,

src/backend/src/structured/sequence/scan-permission.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ module.exports = new Sequence([
5656
}
5757
},
5858
async function explode_permission (a) {
59-
const { reading, permission_options } = a.values();
59+
let { reading, permission_options } = a.values();
60+
61+
// VERY nasty bugs can happen if this array is not cloned!
62+
// (this was learned the hard way)
63+
permission_options = [...permission_options];
64+
6065
for ( let i=0 ; i < permission_options.length ; i++ ) {
6166
const permission = permission_options[i];
6267
permission_options[i] =

src/backend/src/unstructured/permission-scanners.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,22 @@ const PERMISSION_SCANNERS = [
213213

214214
const app_uid = actor.type.app.uid;
215215

216+
const issuer_actor = actor.get_related_actor(UserActorType);
217+
const issuer_reading = await a.icall('scan', issuer_actor, permission_options);
218+
216219
for ( const permission of permission_options ) {
217220
{
221+
218222
const implied = default_implicit_user_app_permissions[permission];
219223
if ( implied ) {
220224
reading.push({
221-
$: 'option',
222-
source: 'implied',
225+
$: 'path',
226+
permission,
227+
source: 'user-app-implied',
223228
by: 'user-app-hc-1',
224229
data: implied,
230+
issuer_username: actor.type.user.username,
231+
reading: issuer_reading,
225232
});
226233
}
227234
} {
@@ -233,11 +240,13 @@ const PERMISSION_SCANNERS = [
233240
}
234241
if ( implicit_permissions[permission] ) {
235242
reading.push({
236-
$: 'option',
243+
$: 'path',
237244
permission,
238-
source: 'implied',
245+
source: 'user-app-implied',
239246
by: 'user-app-hc-2',
240247
data: implicit_permissions[permission],
248+
issuer_username: actor.type.user.username,
249+
reading: issuer_reading,
241250
});
242251
}
243252
}
@@ -246,7 +255,7 @@ const PERMISSION_SCANNERS = [
246255
let sql_perm = permission_options.map(() =>
247256
`\`permission\` = ?`).join(' OR ');
248257
if ( permission_options.length > 1 ) sql_perm = '(' + sql_perm + ')';
249-
258+
250259
// SELECT permission
251260
const rows = await db.read(
252261
'SELECT * FROM `user_to_app_permissions` ' +

src/backend/src/util/debugutil.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const LETTERS = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N'];
2+
3+
let curr_letter_ = 0;
4+
5+
const ind = () => {
6+
let v = curr_letter_;
7+
curr_letter_++;
8+
curr_letter_ = curr_letter_ % LETTERS.length;
9+
return v;
10+
};
11+
12+
module.exports = {
13+
get_a_letter: () => LETTERS[ind()],
14+
cylog: (...a) => {
15+
console.log(`\x1B[36;1m`, ...a);
16+
}
17+
};

0 commit comments

Comments
 (0)