CVE-2022-4768 (published 2022-12-27T23:15Z)

A vulnerability was found in Dropbox merou. It has been classified as critical. Affected is the function add_public_key of the file grouper/public_key.py of the component SSH Public Key Handler. The manipulation of the argument public_key_str leads to injection. It is possible to launch the attack remotely. The name of the patch is d93087973afa26bc0a2d0a5eb5c0fde748bdd107. It is recommended to apply a patch to fix this issue. VDB-216906 is the identifier assigned to this vulnerability.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-74
cwe_name: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
extended_description: Software or other automated logic has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features that classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed.
         

Fix information:
repo_url: https://github.com/dropbox/merou
commit_details: repo_url: https://github.com/dropbox/merou
author: Jing Wang
author_date: 2022-03-28 16:25:44-07:00
msg: Block injection attack in ssh public key handling (#673)

Also needed to fix the setup a bit to address a version incompatibility
repository: repo_url: https://github.com/dropbox/merou
repo_name: dropbox/merou
description: Permission management service
repo_language: Python
owner: dropbox
file_changes: filename: public_key.py
change_type: ModificationType.MODIFY
diff: @@ -72,6 +72,13 @@ def add_public_key(session, user, public_key_str):
     except sshpubkeys.InvalidKeyException as e:
         raise PublicKeyParseError(str(e))
 
+    # Allowing newlines can lead to injection attacks depending on how the key is
+    # consumed, such as if it's dumped in an authorized_keys file with a `command`
+    # restriction.
+    # Note parsing the key is insufficient to block this.
+    if "\r" in public_key_str or "\n" in public_key_str:
+        raise PublicKeyParseError("Public key cannot have newlines")
+
     try:
         get_plugin_proxy().will_add_public_key(pubkey)
     except PluginRejectedPublicKey as e:

programming_language: Python
filename: constants.py
change_type: ModificationType.MODIFY
diff: @@ -16,6 +16,15 @@ SSH_KEY_2 = (
 
 SSH_KEY_BAD = "ssh-rsa AAAblahblahkey some-comment"
 
+SSH_KEY_BAD_MULTILINE = SSH_KEY_1 + "\r" + SSH_KEY_2
+
+SSH2_KEY_BAD = """\
+---- BEGIN SSH2 PUBLIC KEY ----
+foobar: this is a chance to hide bad things
+AAAAC3NzaC1lZDI1NTE5AAAAIJ5O/AXibtVhySDYn60ATXftAU1oCe4BQubFYoV2juEb
+---- END SSH2 PUBLIC KEY ----
+"""
+
 SSH_KEY_RSA_1024 = (
     "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDhKgSsCJR9UyQa/Gsheb5F56hg23CVnCLpmpyC2JMqVEptG9CL83Oft"
     "pOPvEb/785Act4En1VFvwMwTj25VurbG3XI984csiNdWPlM1ke4lHK2PQepSYyZVYn+hhXhzSILNDixhBYeDVv4GOfJM1"

programming_language: Go
filename: public_key_test.py
change_type: ModificationType.MODIFY
diff: @@ -11,7 +11,7 @@ from grouper.public_key import (
     get_public_keys_of_user,
     PublicKeyParseError,
 )
-from tests.constants import SSH_KEY_1, SSH_KEY_BAD
+from tests.constants import SSH2_KEY_BAD, SSH_KEY_1, SSH_KEY_BAD, SSH_KEY_BAD_MULTILINE
 from tests.fixtures import session, users  # noqa: F401
 
 
@@ -41,6 +41,16 @@ def test_bad_key(session, users):  # noqa: F811
     assert get_public_keys_of_user(session, user.id) == []
 
 
+@pytest.mark.parametrize("key", [SSH_KEY_BAD_MULTILINE, SSH2_KEY_BAD])
+def test_multiline_key(key, session, users):  # noqa: F811
+    user = users["cbguder@a.co"]
+
+    with pytest.raises(PublicKeyParseError, match="Public key cannot have newlines"):
+        add_public_key(session, user, key)
+
+    assert get_public_keys_of_user(session, user.id) == []
+
+
 @patch("grouper.public_key.get_plugin_proxy")
 def test_rejected_key(get_plugin_proxy, session, users):  # noqa: F811
     get_plugin_proxy.return_value = PluginProxy([PublicKeyPlugin()])

programming_language: Python