Created
February 3, 2015 09:40
-
-
Save hugdx/33b0060431f8f20ad1a7 to your computer and use it in GitHub Desktop.
Add open_basedir to lessjs when run with nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs; | |
try | |
{ | |
fs = require("graceful-fs"); | |
} | |
catch(e) | |
{ | |
fs = require("fs"); | |
} | |
/** | |
* Edited file less-node/fs.js | |
* Add open_basedir to lessjs, Thanks @gimenete https://gist.github.com/gimenete/9377962 | |
* To use open_basedir, add variable open_basedir to "enviroment" | |
* example: export open_basedir="/test_open_basedir/"; lessc test.less > test.css | |
*/ | |
if( typeof(process.env.open_basedir) == "string" && process.env.open_basedir.length ){ | |
var basedir = process.env.open_basedir; | |
var _fs = { | |
readFile: fs.readFile, | |
stat: fs.stat | |
}; | |
fs.readFile = function(filename) { | |
if (filename.indexOf(basedir) !== 0) { | |
return arguments[arguments.length-1](new Error('Forbidden')) | |
} | |
return _fs.readFile.apply(fs, arguments) | |
} | |
fs.stat = function(filename) { | |
if (filename.indexOf(basedir) !== 0) { | |
return arguments[arguments.length-1](new Error('Forbidden')) | |
} | |
return _fs.stat.apply(fs, arguments) | |
} | |
} | |
//console.log( "/* env:" + JSON.stringify(process.env, null, 2) + " */"); | |
module.exports = fs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment