+ "details": "### Impact\nThe `layout`, `render`, and `include` tags allow arbitrary file access via absolute paths (either as string literals or through Liquid variables when `dynamicPartials: true` is enabled). This poses a security risk when malicious users are allowed to control the template content or specify the filepath to be included as a Liquid variable.\n\n### Patches\nThe issue is fixed via [#855](https://github.com/harttle/liquidjs/pull/855) and published version 10.25.0 on npm.\n\n### Workarounds\n#### Change the files in build time\nIn build time, through Shell script or Webpack `string-replace-loader`, change the file content of correxponding file (depending on your package `type`, for CommonJS it's `dist/liquid.node.js`) under `dist/`, \n\n```diff\n if (fs.fallback !== undefined) {\n const filepath = fs.fallback(file)\n- if (filepath !== undefined) yield filepath\n+ if (filepath !== undefined) {\n+ for (const dir of dirs) {\n+ if (!enforceRoot || this.contains(dir, filepath)) {\n+ yield filepath\n+ break\n+ }\n+ }\n }\n }\n```\n\n#### Overriding by `fs` LiquidJS option\nAdding a [`fs` option](https://liquidjs.com/api/interfaces/FS.html) to override the [default `fs` implementation](https://github.com/harttle/liquidjs/blob/1b85fdaa9c535021f7030a239a64003af26d31b5/src/fs/fs-impl.ts#L36-L40):\n\n```javascript\nconst { statSync, readFileSync, promises: { stat, readFile } } = require('fs')\nconst { resolve, extname, dirname, sep } = require('path')\n\nconst fs = {\n exists: async (fp) => { try { await stat(fp); return true; } catch { return false } },\n existsSync: (fp) => { try { statSync(fp); return true } catch { return false } },\n resolve: (root, file, ext) => resolve(root, file + (extname(file) ? '' : ext)),\n contains: (root, file) => {\n const r = resolve(root)\n return file.startsWith(r.endsWith(sep) ? r : r + sep)\n },\n readFile: (fp) => readFile(fp, 'utf8'),\n readFileSync: (fp) => readFileSync(fp, 'utf8'),\n fallback: () => undefined,\n dirname,\n sep\n};\n\nconst engine = new Liquid({ fs })\n```\n\n### References\nDiscussions: https://github.com/harttle/liquidjs/pull/851\nCode fix: https://github.com/harttle/liquidjs/pull/855",
0 commit comments