Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell-session: Fixed false positives because of links in command output #2649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions components/prism-shell-session.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-shell-session.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 19 additions & 22 deletions tests/languages/shell-session/info_feature.test
Expand Up @@ -9,39 +9,37 @@ 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"],
" -i"
]]
]],
["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"],
Expand All @@ -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"]
Expand All @@ -65,4 +62,4 @@ foo@bar$ exit

----------------------------------------------------

Checks for the info bash outputs.
Checks for the info bash outputs.
69 changes: 69 additions & 0 deletions 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---"]
]