Skip to content

Commit

Permalink
feat: implicit access from apps to shared appdata dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jun 17, 2024
1 parent a2a10b9 commit 31d4eb0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
21 changes: 15 additions & 6 deletions packages/backend/src/filesystem/FSNodeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,26 @@ module.exports = class FSNodeContext {
return ! this.entry.parent_uid;
}

async getUserPart () {
if ( this.isRoot ) return;
async getPathComponents () {
if ( this.isRoot ) return [];

let path = await this.get('path');
if ( path.startsWith('/') ) path = path.slice(1);
const components = path.split('/');
const userpart = components[0];

return userpart;
return path.split('/');
}

async getUserPart () {
if ( this.isRoot ) return;
const components = await this.getPathComponents();
return components[0];
}

async getPathSize () {
if ( this.isRoot ) return;
const components = await this.getPathComponents();
return components.length;
}

async exists (fetch_options = {}) {
await this.fetchEntry();
if ( ! this.found ) {
Expand Down
20 changes: 16 additions & 4 deletions packages/backend/src/filesystem/hl_operations/hl_write.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const { RootNodeSelector, NodePathSelector } = require("../node/selectors");
const { is_valid_node_name } = require("../validation");
const { HLFilesystemOperation } = require("./definitions");
const { MkTree } = require("./hl_mkdir");
const { Actor } = require("../../services/auth/Actor");

class WriteCommonTrait {
install_in_instance (instance) {
Expand Down Expand Up @@ -186,10 +187,6 @@ class HLWrite extends HLFilesystemOperation {
throw APIError.create('cannot_write_to_root');
}

if ( values.user && ! await chkperm(await parent.get('entry'), values.user.id, 'write') ) {
throw APIError.create('forbidden');
}

try {
// old validator is kept here to avoid changing the
// error messages; eventually is_valid_node_name
Expand Down Expand Up @@ -222,6 +219,21 @@ class HLWrite extends HLFilesystemOperation {
if ( values.offset !== undefined && ! dest_exists ) {
throw APIError.create('offset_without_existing_file');
}

// The correct ACL check here depends on context.
// ll_write checks ACL, but we need to shortcut it here
// or else we might send the user too much information.
{
const node_to_check =
( dest_exists && overwrite && ! dedupe_name )
? destination : parent;

const actor = values.actor ?? Actor.adapt(values.user);
const svc_acl = context.get('services').get('acl');
if ( ! await svc_acl.check(actor, node_to_check, 'write') ) {
throw await svc_acl.get_safe_acl_error(actor, node_to_check, 'write');
}
}

if ( dest_exists ) {
console.log('DESTINATION EXISTS', dedupe_name)
Expand Down
19 changes: 18 additions & 1 deletion packages/backend/src/services/auth/ACLService.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ACLService extends BaseService {
return true;
}
}

// app-under-user only works if the user also has permission
if ( actor.type instanceof AppUnderUserActorType ) {
const user_actor = new Actor({
Expand All @@ -88,6 +88,23 @@ class ACLService extends BaseService {

if ( ! user_perm ) return false;
}

// Hard rule: if app-under-user is accessing appdata directory
// under a **different user**, allow,
// IFF that appdata directory is shared with user
// (by "user also has permission" check above)
if (await (async () => {
if ( ! (actor.type instanceof AppUnderUserActorType) ) {
return false;
}
if ( await fsNode.getUserPart() === actor.type.user.username ) {
return false;
}
const components = await fsNode.getPathComponents();
if ( components[1] !== 'AppData' ) return false;
if ( components[2] !== actor.type.app.uid ) return false;
return true;
})()) return true;

const svc_permission = await context.get('services').get('permission');

Expand Down

0 comments on commit 31d4eb0

Please sign in to comment.