From 0d2f588cfe0dedf7d9d0cc4532dfe08fbff1d1d2 Mon Sep 17 00:00:00 2001 From: RunDevelopment Date: Fri, 20 Nov 2020 16:36:24 +0100 Subject: [PATCH] Shell-session: Fixed false positives in output --- components/prism-shell-session.js | 30 ++++---- components/prism-shell-session.min.js | 2 +- .../languages/shell-session/info_feature.test | 41 +++++------ tests/languages/shell-session/issue2644.test | 69 +++++++++++++++++++ 4 files changed, 104 insertions(+), 38 deletions(-) create mode 100644 tests/languages/shell-session/issue2644.test diff --git a/components/prism-shell-session.js b/components/prism-shell-session.js index ce0b2fe05e..d3d07af539 100644 --- a/components/prism-shell-session.js +++ b/components/prism-shell-session.js @@ -14,24 +14,24 @@ ].join('|'); Prism.languages['shell-session'] = { - 'info': { - // foo@bar:~/files$ exit - // foo@bar$ exit - pattern: /^[^\r\n$#*!]+(?=[$#])/m, - alias: 'punctuation', - inside: { - 'path': { - pattern: /(:)[\s\S]+/, - lookbehind: true - }, - 'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/, - 'punctuation': /:/ - } - }, 'command': { - pattern: RegExp(/[$#](?:[^\\\r\n'"<]|\\.|<>)+/.source.replace(/<>/g, function () { return strings; })), + pattern: RegExp(/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?)?[$#](?:[^\\\r\n'"<]|\\.|<>)+/.source.replace(/<>/g, function () { return strings; }), 'm'), greedy: true, inside: { + 'info': { + // foo@bar:~/files$ exit + // foo@bar$ exit + pattern: /^[^#$]+/, + alias: 'punctuation', + inside: { + 'path': { + pattern: /(:)[\s\S]+/, + lookbehind: true + }, + 'user': /^[^:]+/, + 'punctuation': /:/ + } + }, 'bash': { pattern: /(^[$#]\s*)[\s\S]+/, lookbehind: true, diff --git a/components/prism-shell-session.min.js b/components/prism-shell-session.min.js index f066a64b2a..86fc617d64 100644 --- a/components/prism-shell-session.min.js +++ b/components/prism-shell-session.min.js @@ -1 +1 @@ -!function(s){var n=["([\"'])(?:\\\\[^]|\\$\\([^)]+\\)|\\$(?!\\()|`[^`]+`|(?!\\1)[^\\\\`$])*\\1","<<-?\\s*([\"']?)(\\w+)\\2\\s[^]*?[\r\n]\\3"].join("|");s.languages["shell-session"]={info:{pattern:/^[^\r\n$#*!]+(?=[$#])/m,alias:"punctuation",inside:{path:{pattern:/(:)[\s\S]+/,lookbehind:!0},user:/^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,punctuation:/:/}},command:{pattern:RegExp("[$#](?:[^\\\\\r\n'\"<]|\\\\.|<>)+".replace(/<>/g,function(){return n})),greedy:!0,inside:{bash:{pattern:/(^[$#]\s*)[\s\S]+/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#]/,alias:"important"}}},output:/.(?:.*(?:[\r\n]|.$))*/},s.languages["sh-session"]=s.languages.shellsession=s.languages["shell-session"]}(Prism); \ No newline at end of file +!function(s){var n=["([\"'])(?:\\\\[^]|\\$\\([^)]+\\)|\\$(?!\\()|`[^`]+`|(?!\\1)[^\\\\`$])*\\1","<<-?\\s*([\"']?)(\\w+)\\2\\s[^]*?[\r\n]\\3"].join("|");s.languages["shell-session"]={command:{pattern:RegExp('^(?:[^\\s@:$#*!/\\\\]+@[^\\s@:$#*!/\\\\]+(?::[^\0-\\x1F$#*?"<>:;|]+)?)?[$#](?:[^\\\\\r\n\'"<]|\\\\.|<>)+'.replace(/<>/g,function(){return n}),"m"),greedy:!0,inside:{info:{pattern:/^[^#$]+/,alias:"punctuation",inside:{path:{pattern:/(:)[\s\S]+/,lookbehind:!0},user:/^[^:]+/,punctuation:/:/}},bash:{pattern:/(^[$#]\s*)[\s\S]+/,lookbehind:!0,alias:"language-bash",inside:s.languages.bash},"shell-symbol":{pattern:/^[$#]/,alias:"important"}}},output:/.(?:.*(?:[\r\n]|.$))*/},s.languages["sh-session"]=s.languages.shellsession=s.languages["shell-session"]}(Prism); \ No newline at end of file diff --git a/tests/languages/shell-session/info_feature.test b/tests/languages/shell-session/info_feature.test index 446c8b3910..fbb6e4b2b1 100644 --- a/tests/languages/shell-session/info_feature.test +++ b/tests/languages/shell-session/info_feature.test @@ -9,25 +9,24 @@ foo@bar$ exit ---------------------------------------------------- [ - ["info", [ - ["user", "foo@bar"], - ["punctuation", ":"], - ["path", "/var/local"] - ]], ["command", [ + ["info", [ + ["user", "foo@bar"], + ["punctuation", ":"], + ["path", "/var/local"] + ]], ["shell-symbol", "$"], ["bash", [ ["builtin", "cd"], " ~" ]] ]], - - ["info", [ - ["user", "foo@bar"], - ["punctuation", ":"], - ["path", "~"] - ]], ["command", [ + ["info", [ + ["user", "foo@bar"], + ["punctuation", ":"], + ["path", "~"] + ]], ["shell-symbol", "$"], ["bash", [ ["function", "sudo"], @@ -35,13 +34,12 @@ foo@bar$ exit ]] ]], ["output", "[sudo] password for foo:\r\n"], - - ["info", [ - ["user", "root@bar"], - ["punctuation", ":"], - ["path", "~"] - ]], ["command", [ + ["info", [ + ["user", "root@bar"], + ["punctuation", ":"], + ["path", "~"] + ]], ["shell-symbol", "#"], ["bash", [ ["builtin", "echo"], @@ -51,11 +49,10 @@ foo@bar$ exit ]] ]], ["output", "hello!\r\n\r\n"], - - ["info", [ - ["user", "foo@bar"] - ]], ["command", [ + ["info", [ + ["user", "foo@bar"] + ]], ["shell-symbol", "$"], ["bash", [ ["builtin", "exit"] @@ -65,4 +62,4 @@ foo@bar$ exit ---------------------------------------------------- -Checks for the info bash outputs. +Checks for the info bash outputs. \ No newline at end of file diff --git a/tests/languages/shell-session/issue2644.test b/tests/languages/shell-session/issue2644.test new file mode 100644 index 0000000000..ff2c2b2f6a --- /dev/null +++ b/tests/languages/shell-session/issue2644.test @@ -0,0 +1,69 @@ +$ export BORG_PASSCOMMAND="security find-generic-password -a $USER -s borg-passphrase -w" +$ export BORG_RSH="ssh -i ~/.ssh/borg" +$ borg init --encryption=keyfile-blake2 "borg@1.2.3.4:backup" + +By default repositories initialized with this version will produce security +errors if written to with an older version (up to and including Borg 1.0.8). + +If you want to use these older versions, you can disable the check by running: +borg upgrade --disable-tam ssh://borg@1.2.3.4/./backup + +See https://borgbackup.readthedocs.io/en/stable/changes.html#pre-1-0-9-manifest-spoofing-vulnerability for details about the security implications. + +IMPORTANT: you will need both KEY AND PASSPHRASE to access this repo! +Use "borg key export" to export the key, optionally in printable format. +Write down the passphrase. Store both at safe place(s). + +--- + +---------------------------------------------------- + +[ + ["command", [ + ["shell-symbol", "$"], + ["bash", [ + ["builtin", "export"], + ["assign-left", [ + "BORG_PASSCOMMAND" + ]], + ["operator", [ + "=" + ]], + ["string", [ + "\"security find-generic-password -a ", + ["environment", "$USER"], + " -s borg-passphrase -w\"" + ]] + ]] + ]], + ["command", [ + ["shell-symbol", "$"], + ["bash", [ + ["builtin", "export"], + ["assign-left", [ + "BORG_RSH" + ]], + ["operator", [ + "=" + ]], + ["string", [ + "\"ssh -i ~/.ssh/borg\"" + ]] + ]] + ]], + ["command", [ + ["shell-symbol", "$"], + ["bash", [ + "borg init --encryption", + ["operator", [ + "=" + ]], + "keyfile-blake2 ", + ["string", [ + "\"borg@1.2.3.4:backup\"" + ]] + ]] + ]], + + ["output", "By default repositories initialized with this version will produce security\nerrors if written to with an older version (up to and including Borg 1.0.8).\n\nIf you want to use these older versions, you can disable the check by running:\nborg upgrade --disable-tam ssh://borg@1.2.3.4/./backup\n\nSee https://borgbackup.readthedocs.io/en/stable/changes.html#pre-1-0-9-manifest-spoofing-vulnerability for details about the security implications.\n\nIMPORTANT: you will need both KEY AND PASSPHRASE to access this repo!\nUse \"borg key export\" to export the key, optionally in printable format.\nWrite down the passphrase. Store both at safe place(s).\n\n---"] +] \ No newline at end of file