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

libssh2: Print user with verbose flag #16430

Closed
wants to merge 1 commit into from

Conversation

samueldr
Copy link
Contributor

@samueldr samueldr commented Feb 21, 2025

Hi! 👋

A small quality-of-life improvement, I think.

Do tell if I'm missing something here, and there were any reason not to print out the conn->user value that ends-up used for the connection.


This change:

  • Breaks out the existing print out of the LIBSSH2_DEBUG compile-time flag
  • Adds (single) quotation marks around the string to better expose the actual value
  • Adds a NULL print, mirroring other verbose prints in libssh2

Why was this done?

I was trying out the sftp option in curl, and found myself hitting an issue where I was not able to get curl to tell me which username it was using to connect to a host.

With this change, the User: line is printed with -v, just like other SSH verbose prints.

Instead of using the pattern used with SSH MD5 public key, where a ternary is used to print NULL on NULL values, it is using a different branch to add quotes around the string value.

The quotes around the string value are used to better expose to the user an empty string value, compared to "no-value".


Further thoughts:

  • Should the line be prefixed with SSH , to form SSH User: 'samuel'?
  • Is there a pattern I could have used to better pretty-print "quoted strings"?
  • Was it truly necessary to add the NULL print? Is it even a possibility that NULL us present at this location? (I presumed so, from the existing check.)

This change:

 - Breaks out the existing print out of the LIBSSH2_DEBUG compile-time flag
 - Adds (single) quotation marks around the string to better expose the actual value
 - Adds a NULL print, mirroring other verbose prints in libssh2

Why was this done?

I was trying out the `sftp` option in `curl`, and found myself hitting an
issue where I was not able to get curl to tell me which username it was
using to connect to a host.

With this change, the `User: ` line is printed with `-v`, just like other
SSH verbose prints.

Instead of using the pattern used with *SSH MD5 public key*, where a
ternary is used to print `NULL` on NULL values, it is using a different
branch to add quotes around the string value.

The quotes around the string value are used to better expose to the user
an empty string value, compared to "no-value".
infof(data, "User: '%s'", conn->user);
}
else {
infof(data, "User: NULL");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do the same for Password:, for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, this slots in with the two final "further thought" points. I'll leave this to the maintainers to make the call.

Though the reason I did not do it is I considered the latter a purely debug print (i.e. compile-time flag).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to keep this consistent IMO.

@@ -3167,10 +3167,13 @@ static CURLcode ssh_connect(struct Curl_easy *data, bool *done)

sshc = &conn->proto.sshc;

#ifdef CURL_LIBSSH2_DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this would better be kept under the DEBUG flag.
Username is sensitive information and should not be
dumped into the log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't intend to question your opinion on this, but I'm wondering if I missed that there is precedent around this. (To be fair, I did not try to find documentation about what is considered sensitive and not to be logged.)


My quick and biased first thought seems to indicate it's at least not sensitive for HTTP.

~ $ curl -v 'http://obviouslyusername:obviouslypassword@example.com/' 2>&1 | grep obviously
* Server auth using Basic with user 'obviouslyusername'

~ $ curl -v --user obviouslyusername:obviouslypassword 'http://@example.com/' 2>&1 | grep obviously
* Server auth using Basic with user 'obviouslyusername'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been added in 2003. It was a different environment. That username was sent over the wire unencrypted anyway. Nowadays I think it's not prudent to dump credentials into a log.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think user name is still fine, and since curl already shows the user name in the log for other protocols it seems inconsistent to deny it here. It is useful for debugging.

@testclutch
Copy link

Analysis of PR #16430 at 4697b40c:

Test http/test_09_push.py::TestPush::test_09_02_h2_push failed, which has NOT been flaky recently, so there could be a real issue in this PR.

Generated by Testclutch

@bagder bagder closed this in 0cd2670 Mar 4, 2025
@bagder
Copy link
Member

bagder commented Mar 4, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants