@rhinostone/swig-core 2.8.2 → 2.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/backend.js CHANGED
@@ -391,9 +391,10 @@ exports.compile = function (template, parents, options, blockName) {
391
391
  // else verbatim string fallback preserves the userland setTag
392
392
  // path (compile functions that still hand in raw JS-source
393
393
  // fragments). `resolveFrom` is a plain filesystem path that must
394
- // be JSON-escaped into a string literal — the frontend's
395
- // include-tag parse handler has already applied a `\\` → `\\\\`
396
- // backslash escape before handing it off. `ignoreMissing` wraps
394
+ // be escaped into a string literal — escapeTextValue below (backslash,
395
+ // newline, double-quote) is the single chokepoint that does it for all
396
+ // five node types, every flavor and userland setTag, so no unescaped
397
+ // filename can break out of the literal (GHSA-q89c). `ignoreMissing` wraps
397
398
  // the emission in `try { ... } catch (e) {}` so missing-file
398
399
  // errors collapse to the empty string.
399
400
  var incPathJS, incCtxJS;
@@ -419,7 +420,7 @@ exports.compile = function (template, parents, options, blockName) {
419
420
  }
420
421
  out += (node.ignoreMissing ? ' try {\n' : '') +
421
422
  '_output += _swig.compileFile(' + incPathJS + ', {' +
422
- 'resolveFrom: "' + node.resolveFrom + '"' +
423
+ 'resolveFrom: "' + escapeTextValue(node.resolveFrom || '') + '"' +
423
424
  '})(' + incSelector + ');\n' +
424
425
  (node.ignoreMissing ? '} catch (e) {}\n' : '');
425
426
  return;
@@ -453,7 +454,7 @@ exports.compile = function (template, parents, options, blockName) {
453
454
  } else {
454
455
  incdSelector = '_utils.extend({}, _ctx, ' + incdCtxJS + ')';
455
456
  }
456
- var incdOpts = '{resolveFrom: "' + (node.resolveFrom || '') + '"}';
457
+ var incdOpts = '{resolveFrom: "' + escapeTextValue(node.resolveFrom || '') + '"}';
457
458
  out += (node.ignoreMissing ? ' try {\n' : '') +
458
459
  '_output += (await (await _swig.getTemplate(' + incdPathJS + ', ' + incdOpts + '))(' + incdSelector + ')).output;\n' +
459
460
  (node.ignoreMissing ? '} catch (e) {}\n' : '');
@@ -475,7 +476,7 @@ exports.compile = function (template, parents, options, blockName) {
475
476
  } else {
476
477
  impdPathJS = node.path;
477
478
  }
478
- var impdOpts = '{resolveFrom: "' + (node.resolveFrom || '') + '"}';
479
+ var impdOpts = '{resolveFrom: "' + escapeTextValue(node.resolveFrom || '') + '"}';
479
480
  out += '_ctx.' + node.alias + ' = (await (await _swig.getTemplate(' + impdPathJS + ', ' + impdOpts + '))(_ctx)).exports;\n';
480
481
  return;
481
482
  }
@@ -500,7 +501,7 @@ exports.compile = function (template, parents, options, blockName) {
500
501
  } else {
501
502
  fromdPathJS = node.path;
502
503
  }
503
- var fromdOpts = '{resolveFrom: "' + (node.resolveFrom || '') + '"}';
504
+ var fromdOpts = '{resolveFrom: "' + escapeTextValue(node.resolveFrom || '') + '"}';
504
505
  var fromdBindings = '';
505
506
  utils.each(fromdImports, function (entry) {
506
507
  var bindName = entry.alias || entry.name;
@@ -569,7 +570,7 @@ exports.compile = function (template, parents, options, blockName) {
569
570
  } else {
570
571
  extPathJS = node.path;
571
572
  }
572
- var extOpts = '{resolveFrom: "' + (node.resolveFrom || '') + '"}';
573
+ var extOpts = '{resolveFrom: "' + escapeTextValue(node.resolveFrom || '') + '"}';
573
574
  out += 'var _parentTpl = await _swig.getTemplate(' + extPathJS + ', ' + extOpts + ');\n';
574
575
  out += 'var _parentResult = await _parentTpl(_ctx, _mergedBlocks);\n';
575
576
  out += '_output = _parentResult.output;\n';
package/lib/index.js CHANGED
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * @type {String}
17
17
  */
18
- exports.version = "2.8.2";
18
+ exports.version = "2.8.3";
19
19
 
20
20
  exports.utils = require('./utils');
21
21
  exports.security = require('./security');
package/lib/ir.js CHANGED
@@ -153,7 +153,7 @@
153
153
  * @property {IRExpr} [context] Explicit locals for the included template.
154
154
  * @property {boolean} [isolated] Maps to Twig's `only`.
155
155
  * @property {boolean} [ignoreMissing] Swallow loader errors when the file is missing.
156
- * @property {string} [resolveFrom] Including template's filename (backslash-escaped) for loader-relative resolution.
156
+ * @property {string} [resolveFrom] Including template's filename (escaped at emit time) for loader-relative resolution.
157
157
  * @property {IRLoc} [loc]
158
158
  */
159
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhinostone/swig-core",
3
- "version": "2.8.2",
3
+ "version": "2.8.3",
4
4
  "description": "Shared IR, backend, and runtime for the @rhinostone/swig family of template engines.",
5
5
  "keywords": [
6
6
  "template",