-
-
Notifications
You must be signed in to change notification settings - Fork 596
Description
Trying to decode a password-encrypted message by pasteing it in a terminal:
$ age -d
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNjcnlwdCAzMGNPVU9NVWJFYkZtejdz
dHZQZDhBIDE4ClB2bEo2ako5dGdDcHNvT0F2VGNxSFBMSmxHYjRUcWM0MDlKRnl0
RnFYMUkKLS0tIHBJMGNmNVBub2FCd0tYTFljRmM0UTFML0w0eVN0ckdTcUtTSE9F
UFhzcXcK2kmvabtVqQySkhhw5z2USvSWgQyDe9VEOWlSOwUGzu26cxtEc/uy1DKF
klzTLEnter passphrase:
age: error: incorrect passphrase
age: report unexpected or unhelpful errors at https://filippo.io/age/report
$ -----END AGE ENCRYPTED FILE-----
I would expect the password prompt to appear only after the END AGE footer, but it actually appears while not all of the message has been pasted yet, and ends up reading part of the last Base64 line as password, while leaving the footer be spammed on shell prompt.
This does not occur with all messages, but the one used here was created as follows:
$ age -p -a
Enter passphrase (leave empty to autogenerate a secure one):
Using the autogenerated passphrase "vivid-become-unfold-enable-lunch-enter-cupboard-reason-time-giraffe".
asdfaslkjdlaskjdfsaf
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNjcnlwdCAzMGNPVU9NVWJFYkZtejdz
dHZQZDhBIDE4ClB2bEo2ako5dGdDcHNvT0F2VGNxSFBMSmxHYjRUcWM0MDlKRnl0
RnFYMUkKLS0tIHBJMGNmNVBub2FCd0tYTFljRmM0UTFML0w0eVN0ckdTcUtTSE9F
UFhzcXcK2kmvabtVqQySkhhw5z2USvSWgQyDe9VEOWlSOwUGzu26cxtEc/uy1DKF
klzTLSeQT0za0EU=
-----END AGE ENCRYPTED FILE-----
This should be solved by always waiting for the footer before stopping, and prior to asking for a password.
I would recommend doing so even if invalid data was detected in the middle, to avoid spamming the rest of the message on shell prompt. A malicious malformed message could contain commands such as rm -rf ~ in the middle of a long armor sequence that then inadvertently get executed by a recipient.
Additionally, the password prompt could be using the tty rather than stdin, or if available, using a GUI prompt for password. Existing password-asking programs employ both of these methods. Using a tty for password input allows it to work on interactive console even when stdin, stdout and stderr are all redirected, and in particular when Age gets its input data via stdin pipe. Although, changing this would break any existing hacks that feed Age with passwords over stdin (unless they run without a terminal and Age then falls back to reading stdin).