From dc00caa88de5b162cb8bf6aa26071f17c6457de7 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Fri, 27 Oct 2023 15:35:18 -0700 Subject: [PATCH] fix(evasive-transform): replace homoglyphs with boring ascii --- .../evasive-transform/src/transform-comment.js | 6 +++--- .../test/snapshots/test-evade-censor.js.md | 12 ++++++------ .../test/snapshots/test-evade-censor.js.snap | Bin 963 -> 955 bytes .../test/test-transform-comment.js | 6 ++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/evasive-transform/src/transform-comment.js b/packages/evasive-transform/src/transform-comment.js index 87df3ff237..99764b31ed 100644 --- a/packages/evasive-transform/src/transform-comment.js +++ b/packages/evasive-transform/src/transform-comment.js @@ -35,11 +35,11 @@ export function transformComment(node, unmapLoc) { // ...strip extraneous comment whitespace .replace(/^\s+/gm, ' ') // ...replace HTML comments with a defanged version to pass SES restrictions. - .replace(HTML_COMMENT_START_RE, '') + .replace(HTML_COMMENT_START_RE, '') // ...replace import expressions with a defanged version to pass SES restrictions // (featuring homoglyphs for @kriskowal) - .replace(IMPORT_RE, 'im\u{440}ort$2') + .replace(IMPORT_RE, 'IMPORT$2') // ...replace end-of-comment markers .replace(/\*\//g, '*X/'); if (unmapLoc) { diff --git a/packages/evasive-transform/test/snapshots/test-evade-censor.js.md b/packages/evasive-transform/test/snapshots/test-evade-censor.js.md index 7709d4d60b..94af869fa9 100644 --- a/packages/evasive-transform/test/snapshots/test-evade-censor.js.md +++ b/packages/evasive-transform/test/snapshots/test-evade-censor.js.md @@ -8,19 +8,19 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 - '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {imрort(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' + '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {IMPORT(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' ## evadeCensor() - successful source transform w/ source map > Snapshot 1 - '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {imрort(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' + '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {IMPORT(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' ## evadeCensor() - successful source transform w/ source map & source URL > Snapshot 1 - '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {imрort(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' + '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {IMPORT(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' > Snapshot 2 @@ -45,7 +45,7 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 - '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {imрort(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' + '\'use strict\';var node_fs=require(\'node:fs\');/** * @returns {IMPORT(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' > Snapshot 2 @@ -70,13 +70,13 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 - '\'use strict\';varnode_fs=require(\'node:fs\');/** * @returns {imрort(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' + '\'use strict\';varnode_fs=require(\'node:fs\');/** * @returns {IMPORT(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' ## evadeCensor() - successful source transform w/ source map, source URL & unmapping > Snapshot 1 - '\'use strict\';varnode_fs=require(\'node:fs\');/** * @returns {imрort(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' + '\'use strict\';varnode_fs=require(\'node:fs\');/** * @returns {IMPORT(\'node:fs\').constants.F_OK} */function bambalam(){return node_fs.constants.F_OK;}/** * */function monkey(){return true;}exports.bambalam=bambalam;exports.monkey=monkey;/*# sourceMappingURL=index.cjs.map*/' > Snapshot 2 diff --git a/packages/evasive-transform/test/snapshots/test-evade-censor.js.snap b/packages/evasive-transform/test/snapshots/test-evade-censor.js.snap index bf397da7ea77821f10de2639122c784bbb888b3c..391945013cc63bcfc35b67a62354e0a7d158408e 100644 GIT binary patch literal 955 zcmV;s14R5mRzVN%-OQ-5m5EIg+HoQACSvc zs7qg_86S%X00000000B+R?BYFKos>PO&`^)p$~Nd5_H8Mu%P7|kdRpL3oKai2dvnzWWgQV6Pr-+XbT$>>5gyiV}i!{K$8*%o(< zCSP+s{&>GuGd$xy($h+xB7P{NjHE81tj{Ut9O4D_`OM*Xr@XjSSzbv*Oqs63J;U+%)WT}z<}S`n*L}zIEZ4zR!>$?) z!ycd52?69x9ZC7!aGKfC!X)Mtx)sBF z%%}NXy4i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4>WQg@A7@LFqj~Clu7BppznvIKAjfM0SLl zj_5i{M|@o5QI?*x^z<~Zm2`DTSBJP~(wdRh&hYe0duMa)=#m5}qt=vrn)l+E)Y9%( z?S9qnSM7fF&->NnaXz+uCp!NJd=?k?^sdYMdRM!3{oYsc+>r~VCP?PsqHVW}_E-2O z_5C2esYB=60eSfc_~vwiZvq+!`9_abK?p*d5<@G+ln$Yo^?ei*0v07Axf?LdvIcr# zO^nkQwFJ8qTk&Ix0fXL1P>ewE1M8BO$UWc~5@#2xGjTw`FeHW#spZ4L)baxzjatqD lGh{)of!qUOAkRSFfV}?|wd_K`=l_dZege5pVpsnX005fh)NTL( diff --git a/packages/evasive-transform/test/test-transform-comment.js b/packages/evasive-transform/test/test-transform-comment.js index 0e0318ec5c..6a13033836 100644 --- a/packages/evasive-transform/test/test-transform-comment.js +++ b/packages/evasive-transform/test/test-transform-comment.js @@ -24,7 +24,7 @@ test('transformComment() - defang HTML comment', async t => { value: '', }); transformComment(comment); - t.is(comment.value, ''); + t.is(comment.value, ''); }); test('transformComment() - rewrite suspicious import(...)', async t => { @@ -37,9 +37,7 @@ test('transformComment() - rewrite suspicious import(...)', async t => { transformComment(comment); t.regex( comment.value, - new RegExp( - "\\* @type \\{im\u{440}ort\\('c:\\\\My Documents\\\\user\\.js'\\)", - ), + new RegExp("\\* @type \\{IMPORT\\('c:\\\\My Documents\\\\user\\.js'\\)"), ); });