Skip to content

Conversation

@a7p
Copy link

@a7p a7p commented Jul 2, 2019

No description provided.

for filename in filenames:
with open(filename, 'r', errors='ignore') as content:
text_body = content.read()
with io.open(filename, 'rb') as content:
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather see io.open(filename, encoding='UTF-8') -- errors='ignore' can lead to false negatives

Copy link
Author

Choose a reason for hiding this comment

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

providing an encoding does not solve my issue (a file which is not utf-8 encoded).

Using ignore means throwing away the characters which cannot be decoded as UTF-8. Since the AWS-Credentials will be ASCII-Strings (this is me claiming something without having any prove) it may only lead to false positives, which would not be that bad imo. I can try to provide further information on this and tests for various scenarios, but it will take a few weeks.

Copy link
Member

Choose a reason for hiding this comment

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

afaik, ignore=... and replace=... can remove bytes surrounding an error (consider a surrogate or continuation byte followed by garbage) so they could in fact remove part of the key leading to no-match

Copy link
Author

Choose a reason for hiding this comment

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

Sounds plausible to me, I did not know about this. The question is, what is the expected behavior for detect-aws-credentials on non-utf-8 files? I could live with skipping them or with opening them as utf-8 with ignore or replace - in none of these scenarios credential-detection will not (reliably) work for the file, as you pointed out. I cannot see how to build an encoding agnostic solution. If you've got any idea I'll happy to do try to implement it.

Copy link
Member

Choose a reason for hiding this comment

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

another idea would be to scan the files as binary files and use the bytes representation of the credentials -- then you don't worry about the encoding

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

thank you very much - I'll look into it and try to come up with a PR next weekend.

Copy link
Contributor

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

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

I fail to understand the purpose of this change. If it is a bugfix it should refer to an existing bug that documents clearly the problem.

Based on its title, I would directly close the PR as I don't find ignoring errors as a good practice in general.

@asottile
Copy link
Member

asottile commented Aug 4, 2019

I fail to understand the purpose of this change. If it is a bugfix it should refer to an existing bug that documents clearly the problem.

Based on its title, I would directly close the PR as I don't find ignoring errors as a good practice in general.

we're iterating on the hook as seen above -- there's a way to make this work without dealing with encoding problems

@asottile
Copy link
Member

via #453 -- thanks again for working on this!

@asottile asottile closed this Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants