Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Verbose param leaks passwords from basic auth #120

Closed
bwright86 opened this issue Dec 10, 2020 · 15 comments · Fixed by #123
Closed

Verbose param leaks passwords from basic auth #120

bwright86 opened this issue Dec 10, 2020 · 15 comments · Fixed by #123

Comments

@bwright86
Copy link

I'm new to using the module, and noticed that -Verbose will return details from the Invoke-RestMethod call, which includes the username/password in the Body block.

This behavior could lead to leaked passwords for users, either from peers sitting beside you, or from Powershell transcripts capturing output in text files (This is the case for me, as i have to go back and scrub the file).

It would be easy to add a -Verbose:$false in the below text to prevent leaking password details:

$response = Invoke-TppRestMethod @params

There may be other locations that could leak this detail as well, I will post them as I find them.

It looks like there is a push to move to Token Based authentication in the future, which is a good move. But Tokens are still sensitive, so it would probably be helpful to prevent leaking those as well.

I would be curious if there is a use case where returning the verbose detail from this call would be necessary, if there is a case, some mechanism that is difficult to trigger could be implemented to allow it to be returned.

@bwright86
Copy link
Author

It looks like this cmdlet would do the same:

$response = Invoke-TppRestMethod @params

(Not sure if this is the case only for OAuth or if Integrated UseDefaultCredentials would do the same.)

@bwright86
Copy link
Author

Looks like these cmdlets as well:

$params.Body.Add('Password', $plainTextPassword)

$params.Body.Password = $plainTextPassword

@gdbarron
Copy link
Owner

Hey @bwright86, thanks for submitting this. I've been meaning to do this for a while and just never got around to it 😄

I'd like to keep the verbose output for all the other rest params which I've found to be very helpful. I will look to just hide the private/secret info. Providing the location where the info should be hidden is a big help, thanks. I'll get working on this.

@bwright86
Copy link
Author

bwright86 commented Dec 13, 2020 via email

@gdbarron
Copy link
Owner

Nice work on the patch! I took a similar approach, but with some differences. I wanted to be able to capture the params on the way in and verbose on the way out so I created a function to handle both. Let me know what you think. https://github.com/gdbarron/VenafiTppPS/compare/hide-verbose-logging-secrets

The code isn't finished yet, but should be mostly functional.

@bwright86
Copy link
Author

Cool, I like the idea of splitting the function out to its own cmdlet.

I will pull this down tomorrow and give it a whirl.

Thanks for looking into it!

@gdbarron
Copy link
Owner

Hey @bwright86. Get a chance to give it a shot? Thanks.

@gdbarron
Copy link
Owner

Looks like these cmdlets as well:

$params.Body.Add('Password', $plainTextPassword)

$params.Body.Password = $plainTextPassword

These don't write-verbose directly, but leave it to Invoke-TppRestMethod to write it out so updating that one function covers these.

@gdbarron gdbarron linked a pull request Dec 19, 2020 that will close this issue
gdbarron pushed a commit that referenced this issue Dec 19, 2020
@gdbarron
Copy link
Owner

I had missed hiding the Authorization value in the header, but have now added that as well, 16ddae4

@bwright86
Copy link
Author

bwright86 commented Dec 20, 2020 via email

@bwright86
Copy link
Author

I pulled down the changes you made, and moved it into a patched version "2.0.5.2" on my side to test. It seems i am still leaking passwords w/ the Verbose parameter.

I'm guessing the issue on my side is around the Regex expressions being used, but i don't have the time currently to dive into the expressions. I am currently using PSv5.1 on my side.

Would it be difficult to walk through the hashtable to look for sensitive data, versus searching through JSON strings w/ RegEx?

@gdbarron
Copy link
Owner

It's a hashtable going in, but json coming out so went with the approach I did. I'm open to other ideas. If you can let me know what commands you are running I can see if I can replicate. I'm using v7.1, but will test with v5.1 as well.

@gdbarron
Copy link
Owner

gdbarron commented Dec 22, 2020

Found the issue. The formatting between v5 and v7 is slightly different where there's an extra space with v5.

# PS v5 has 2 spaces between key:  value
# PS v7 has 1 space between key: value

I've updated the branch. As I said, I'm definitely open to other ideas as I don't love this approach, but it seems better than recursing hashtables, json, etc with nested key/value pairs.

@bwright86
Copy link
Author

bwright86 commented Dec 23, 2020 via email

@bwright86
Copy link
Author

bwright86 commented Dec 23, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants