@@ -17,7 +17,7 @@ var rdfVocab = require('./vocab/rdf.js');
1717
1818process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
1919
20- function allow ( mode , req , res ) {
20+ function allow ( mode , req ) {
2121 var options = req . app . locals . ldp ;
2222 var origin = req . get ( 'origin' ) ;
2323 origin = origin ? origin : '' ;
@@ -83,7 +83,7 @@ function allow(mode, req, res) {
8383 if ( rdfVocab . brack ( origin ) === originsControlElem . toString ( ) ) {
8484 debug ( "Found policy for origin: " +
8585 originsControlElem . toString ( ) ) ;
86- originControlValue = allowOrigin ( mode , req , res , userId , aclGraph , controlElem ) ;
86+ originControlValue = allowOrigin ( mode , req , userId , aclGraph , controlElem ) ;
8787 if ( originControlValue ) {
8888 return originControlValue ;
8989 }
@@ -93,7 +93,7 @@ function allow(mode, req, res) {
9393 } else {
9494 debug ( "No origin found, moving on." ) ;
9595 }
96- originControlValue = allowOrigin ( mode , req , res , userId , aclGraph , controlElem ) ;
96+ originControlValue = allowOrigin ( mode , req , userId , aclGraph , controlElem ) ;
9797 if ( originControlValue ) {
9898 return originControlValue ;
9999 }
@@ -174,7 +174,7 @@ function allow(mode, req, res) {
174174 if ( rdfVocab . brack ( origin ) === originsElem . toString ( ) ) {
175175 debug ( "Found policy for origin: " +
176176 originsElem . toString ( ) ) ;
177- originValue = allowOrigin ( mode , req , res , userId , aclGraph , modeElem ) ;
177+ originValue = allowOrigin ( mode , req , userId , aclGraph , modeElem ) ;
178178 if ( originValue ) {
179179 return originValue ;
180180 }
@@ -184,7 +184,7 @@ function allow(mode, req, res) {
184184 } else {
185185 debug ( "No origin found, moving on." ) ;
186186 }
187- originValue = allowOrigin ( mode , req , res , userId , aclGraph , modeElem ) ;
187+ originValue = allowOrigin ( mode , req , userId , aclGraph , modeElem ) ;
188188 if ( originValue ) {
189189 return originValue ;
190190 }
@@ -236,7 +236,7 @@ function allow(mode, req, res) {
236236 } ;
237237}
238238
239- function allowOrigin ( mode , req , res , userId , aclGraph , subject ) {
239+ function allowOrigin ( mode , req , userId , aclGraph , subject ) {
240240 debug ( "In allow origin" ) ;
241241 var ownerStatements = aclGraph . each ( subject , ns . acl ( "owner" ) ,
242242 aclGraph . sym ( userId ) ) ;
@@ -293,11 +293,19 @@ function fetchDocument(graph, uri, req) {
293293 var body = "" ;
294294 if ( S ( uri ) . startsWith ( uriBase ) ) {
295295 try {
296- var documentPath = file . uriToFilename ( S ( uri ) . chompLeft ( uriBase ) . s ,
297- options . root ) ;
296+ var oldPath = req . url ;
297+ var newPath = S ( uri ) . chompLeft ( uriBase ) . s ;
298+ var documentPath = file . uriToFilename ( newPath , options . root ) ;
298299 var documentUri = url . parse ( documentPath ) ;
299300 documentPath = documentUri . pathname ;
301+
302+ //Overwrite url attribute to call allow with the correct path.
303+ //Otherwise enters infinite recuresion.
304+ req . url = newPath ;
300305 var readAllowed = allow ( 'Read' , req ) ;
306+ //Restore value of req.url
307+ req . url = oldPath ;
308+
301309 if ( readAllowed && readAllowed . status === 200 ) {
302310 body = fs . readFileSync ( documentPath , { encoding : 'utf8' } ) ;
303311 }
@@ -379,11 +387,11 @@ exports.allowAppendThenWriteHandler = function(req, res, next) {
379387 if ( ! options . webid ) {
380388 return next ( ) ;
381389 } else {
382- var allowAppendValue = allow ( "Append" , req , res , next ) ;
390+ var allowAppendValue = allow ( "Append" , req ) ;
383391 if ( allowAppendValue . status == 200 ) {
384392 return next ( ) ;
385393 } else {
386- var allowWriteValue = allow ( "Write" , req , res , next ) ;
394+ var allowWriteValue = allow ( "Write" , req ) ;
387395 if ( allowWriteValue . status == 200 ) {
388396 return next ( ) ;
389397 } else {
0 commit comments