Skip to content

Commit 4b57540

Browse files
author
Martin Martinez Rivera
committed
Check if user is allowed to read fetched document before serving it.
1 parent aed3213 commit 4b57540

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎acl.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,18 @@ function fetchDocument(graph, uri, req) {
290290
var options = req.app.locals.ldp;
291291
var uriBase = file.uriBase(req);
292292

293-
var body;
293+
var body = "";
294294
if (S(uri).startsWith(uriBase)) {
295295
try {
296296
var documentPath = file.uriToFilename(S(uri).chompLeft(uriBase).s,
297297
options.root);
298298
var documentUri = url.parse(documentPath);
299299
documentPath = documentUri.pathname;
300-
body = fs.readFileSync(documentPath, {encoding: 'utf8'});
301-
} catch (err) {
302-
body = "";
303-
}
300+
var readAllowed = allow('Read', req);
301+
if (readAllowed && readAllowed.status === 200) {
302+
body = fs.readFileSync(documentPath, {encoding: 'utf8'});
303+
}
304+
} catch (err) {}
304305
} else {
305306
var response = request('GET', uri, {
306307
headers: {

0 commit comments

Comments
 (0)