@@ -109,13 +109,30 @@ describe('Liquid', function () {
109109 } )
110110 } )
111111 describe ( '#renderFile' , function ( ) {
112+ afterEach ( restore )
112113 it ( 'should throw with lookup list when file not exist' , function ( ) {
113114 const engine = new Liquid ( {
114115 root : [ '/boo' , '/root/' ] ,
115116 extname : '.html'
116117 } )
117118 return expect ( engine . renderFile ( '/not/exist.html' ) ) . rejects . toThrow ( / F a i l e d t o l o o k u p " \/ n o t \/ e x i s t .h t m l " i n " \/ b o o , \/ r o o t \/ " / )
118119 } )
120+ it ( 'should reject absolute paths outside root' , async function ( ) {
121+ mock ( {
122+ '/safe/foo.html' : 'safe' ,
123+ '/etc/secret' : 'SECRET'
124+ } )
125+ const engine = new Liquid ( { root : [ '/safe' ] } )
126+ await expect ( engine . renderFile ( '/etc/secret' ) ) . rejects . toThrow ( / F a i l e d t o l o o k u p / )
127+ } )
128+ it ( 'should reject absolute paths outside root (sync)' , function ( ) {
129+ mock ( {
130+ '/safe/foo.html' : 'safe' ,
131+ '/etc/secret' : 'SECRET'
132+ } )
133+ const engine = new Liquid ( { root : [ '/safe' ] } )
134+ expect ( ( ) => engine . renderFileSync ( '/etc/secret' ) ) . toThrow ( / F a i l e d t o l o o k u p / )
135+ } )
119136 } )
120137 describe ( '#parseFile' , function ( ) {
121138 it ( 'should throw with lookup list when file not exist' , function ( ) {
@@ -127,7 +144,7 @@ describe('Liquid', function () {
127144 } )
128145 it ( 'should fallback to require.resolve in Node.js' , async function ( ) {
129146 const engine = new Liquid ( {
130- root : [ '/root/' ] ,
147+ root : [ process . cwd ( ) ] ,
131148 extname : '.html'
132149 } )
133150 const tpls = await engine . parseFileSync ( 'jest' )
0 commit comments