Skip to content

Ruby: add rb/clear-text-storage-sensitive-data query #8306

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

Conversation

alexrford
Copy link
Contributor

No description provided.

@alexrford alexrford force-pushed the ruby/clear-text-storage branch from e04a6bf to 7331681 Compare March 5, 2022 19:32
@alexrford alexrford marked this pull request as ready for review March 5, 2022 21:23
@alexrford alexrford requested a review from a team as a code owner March 5, 2022 21:23
Copy link
Contributor

@hmac hmac left a comment

Choose a reason for hiding this comment

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

This looks good - just a few minor comments and a couple of potential improvements we could make.

private import ruby
private import codeql.ruby.DataFlow
private import codeql.ruby.TaintTracking
import CleartextStorageCustomizations::CleartextStorage
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this import is only required for a use of Source in CleartextStorage.ql - maybe just move this import to that file?

from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
where config.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "Sensitive data returned by $@ is stored here.",
source.getNode(), source.getNode().(Source).describe()
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at some of the results in the DCA evaluation, I wonder if we should report these alerts at the source location rather than the sink location. There seem to be a lot of cases in diaspora/diaspora where a password value flows from a test to a call to User.create or similar. I worry that, since the alert is located at the sink, in models/user.rb, any code-scanning filtering to remove alerts in test files will let it pass through.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like a good idea overall. The case of a sink in test code and source in production code seems far less likely to occur in practice.

# BAD: plaintext password stored to disk
File.new("bar.txt", "a").puts("password: #{new_password}")
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a FP in the evaluation that is this:

random_password = SecureRandom.hex(20)
self.password = random_password

I don't know if this is due to over-sensitivity in CleartextSources or something else, but I bet this is a common pattern and it would be good to not flag it.

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 guess that the intention in the flagged case here is to set the value to a random hash value where the password that hashes to it is unknown, in which case I agree that it's a FP.

My first approximation to fixing this would is to augment to notSensitiveRegexp() expression to include random as a "safe" term. I have some slight concerns that there could be cases where a random plaintext password is generated and assigned to a field (e.g. for initial signup or password reset) - but it seems unlikely that the field that it's written to would work for both hashed and unhashed passwords. Consequently, in this theoretical case I'd expect there to be the same vulnerability when setting a real password that we could hopefully flag up.

@alexrford alexrford requested review from a team as code owners March 10, 2022 00:45
@alexrford alexrford deleted the branch github:alexrford/ruby/orm-write-access March 10, 2022 17:35
@alexrford alexrford closed this Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants