Skip to content

Commit 6a2fbc1

Browse files
committed
fix(security): hoist acl check in ll_read
1 parent ab74f1e commit 6a2fbc1

File tree

1 file changed

+20
-15
lines changed
  • src/backend/src/filesystem/ll_operations

1 file changed

+20
-15
lines changed

src/backend/src/filesystem/ll_operations/ll_read.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ const { buffer_to_stream } = require("../../util/streamutil");
2626
const { TYPE_SYMLINK, TYPE_DIRECTORY } = require("../FSNodeContext");
2727
const { LLFilesystemOperation } = require("./definitions");
2828

29+
const dry_checks = [
30+
async function check_ACL_for_read (a) {
31+
if ( a.get('no_acl') ) return;
32+
const context = a.iget('context');
33+
const svc_acl = context.get('services').get('acl');
34+
const { fsNode, actor } = a.values();
35+
if ( ! await svc_acl.check(actor, fsNode, 'read') ) {
36+
throw await svc_acl.get_safe_acl_error(actor, fsNode, 'read');
37+
}
38+
},
39+
async function type_check_for_read (a) {
40+
const fsNode = a.get('fsNode');
41+
if ( await fsNode.get('type') === TYPE_DIRECTORY ) {
42+
throw APIError.create('cannot_read_a_directory');
43+
}
44+
},
45+
];
46+
2947
class LLRead extends LLFilesystemOperation {
3048
static METHODS = {
3149
_run: new Sequence({
@@ -39,12 +57,7 @@ class LLRead extends LLFilesystemOperation {
3957
throw APIError.create('subject_does_not_exist');
4058
}
4159
},
42-
async function type_check_for_read (a) {
43-
const fsNode = a.get('fsNode');
44-
if ( await fsNode.get('type') === TYPE_DIRECTORY ) {
45-
throw APIError.create('cannot_read_a_directory');
46-
}
47-
},
60+
...dry_checks,
4861
async function resolve_symlink (a) {
4962
let fsNode = a.get('fsNode');
5063
let type = await fsNode.get('type');
@@ -54,15 +67,7 @@ class LLRead extends LLFilesystemOperation {
5467
}
5568
a.set('fsNode', fsNode);
5669
},
57-
async function check_ACL_for_read (a) {
58-
if ( a.get('no_acl') ) return;
59-
const context = a.iget('context');
60-
const svc_acl = context.get('services').get('acl');
61-
const { fsNode, actor } = a.values();
62-
if ( ! await svc_acl.check(actor, fsNode, 'read') ) {
63-
throw await svc_acl.get_safe_acl_error(actor, fsNode, 'read');
64-
}
65-
},
70+
...dry_checks,
6671
async function calculate_has_range (a) {
6772
const { offset, length } = a.values();
6873
const fsNode = a.get('fsNode');

0 commit comments

Comments
 (0)