-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ruby: add rb/clear-text-storage-sensitive-data
query
#8395
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
Co-authored-by: Harry Maclean <[email protected]>
QHelp previews: ruby/ql/src/queries/security/cwe-312/CleartextStorage.qhelpClear-text storage of sensitive informationSensitive information that is stored unencrypted is accessible to an attacker who gains access to the storage. RecommendationEnsure that sensitive information is always encrypted before being stored. In general, decrypt sensitive information only at the point where it is necessary for it to be used in cleartext. Be aware that external processes often store the ExampleThe following example code stores user credentials (in this case, their password) to disk in plain text: class UserSession
def login(username, password)
# ...
logfile = File.open("login_attempts.log")
logfile.puts "login with password: #{password})"
end
end Instead, the credentials should be masked or redacted before storing: class UserSession
def login(username, password)
# ...
password_escaped = password.sub(/.*/, "[redacted]")
logfile = File.open("login_attempts.log")
logfile.puts "login with password: #{password_escaped})"
end
end References
|
QHelp previews: ruby/ql/src/queries/security/cwe-312/CleartextStorage.qhelpClear-text storage of sensitive informationSensitive information that is stored unencrypted is accessible to an attacker who gains access to the storage. RecommendationEnsure that sensitive information is always encrypted before being stored. In general, decrypt sensitive information only at the point where it is necessary for it to be used in cleartext. Be aware that external processes often store the ExampleThe following example code stores user credentials (in this case, their password) to disk in plain text: class UserSession
def login(username, password)
# ...
logfile = File.open("login_attempts.log")
logfile.puts "login with password: #{password})"
end
end Instead, the credentials should be masked or redacted before storing: class UserSession
def login(username, password)
# ...
password_escaped = password.sub(/.*/, "[redacted]")
logfile = File.open("login_attempts.log")
logfile.puts "login with password: #{password_escaped})"
end
end References
|
I guess a suitable DCA run could give some visibility into potential changes. Otherwise Python looks fine to me. @RasmusWL has worked on sensitive data and may have an opinion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only JS/Python change seems to be adding "random"
to notSensitiveRegexp()
, which seems fine to me.
JS 👍
We lose one result in test code for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for Python
I guess a suitable DCA run could give some visibility into potential changes. Otherwise Python looks fine to me.
@RasmusWL
has worked on sensitive data and may have an opinion.We lose one result in test code for
py/clear-text-storage-sensitive-data
in the standard code scanning set. It's not the kind of FP that this change is directly intended to avoid, where this random data represents some hash value. However, the result is low value, being in test code, and doesn't look to me like it would be a common pattern for production code.
Agreed, that result was not interesting 👍
This is #8306 again, which I'm unable to retarget against main and reopen.
The majority of this query is identical to
rb/clear-text-logging-sensitive-data
, with the main differences being in the sinks (file writes and other persistent writes rather than logging calls), and in reporting alerts at the sink rather than the source to make it easier to classify FPs with flow from a test file. The latter change may also be useful for the logging version of this query, but it appears to be a more common case with this query.As this changes the shared
SensitiveDataHeuristics.qll
library, it may have a minor impact on results for JS/Python queries relying on thenotSensitiveRegexp/0
predicate. See the comments at #8306 (comment) for some context on this change.