Shell-session: Fixed false positives because of links in command output (#2649)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
diff --git a/components/prism-shell-session.js b/components/prism-shell-session.js
index ce0b2fe..d3d07af 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'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; })),
+ pattern: RegExp(/^(?:[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?::[^\0-\x1F$#*?"<>:;|]+)?)?[$#](?:[^\\\r\n'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/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 f066a64..86fc617 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'\"<]|\\\\.|<<str>>)+".replace(/<<str>>/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\'"<]|\\\\.|<<str>>)+'.replace(/<<str>>/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 446c8b3..fbb6e4b 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 0000000..ff2c2b2
--- /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