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
Ruby: add stack-trace exposure query #11250
base: main
Are you sure you want to change the base?
Conversation
|
QHelp previews: ruby/ql/src/queries/security/cwe-209/StackTraceExposure.qhelpInformation exposure through an exceptionSoftware developers often add stack traces to error messages, as a debugging aid. Whenever that error message occurs for an end user, the developer can use the stack trace to help identify how to fix the problem. In particular, stack traces can tell the developer more about the sequence of events that led to a failure, as opposed to merely the final state of the software when the error occurred. Unfortunately, the same information can be useful to an attacker. The sequence of class or method names in a stack trace can reveal the structure of the application as well as any internal components it relies on. Furthermore, the error message at the top of a stack trace can include information such as server-side file names and SQL code that the application relies on, allowing an attacker to fine-tune a subsequent injection attack. RecommendationSend the user a more generic error message that reveals less information. Either suppress the stack trace entirely, or log it only on the server. ExampleIn the following example, an exception is handled in two different ways. In the first version, labeled BAD, the exception is exposted to the remote user by rendering it as an HTTP response. As such, the user is able to see a detailed stack trace, which may contain sensitive information. In the second version, the error message is logged only on the server, and a generic error message is displayed to the user. That way, the developers can still access and use the error log, but remote users will not see the information. class UsersController < ApplicationController
def update_bad(id)
do_computation()
rescue => e
# BAD
render e.backtrace, content_type: "text/plain"
end
def update_good(id)
do_computation()
rescue => e
# GOOD
log e.backtrace
redner "Computation failed", content_type: "text/plain"
end
endReferences
|
| from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink | ||
| where config.hasFlowPath(source, sink) | ||
| select sink.getNode(), source, sink, "$@ may be exposed to an external user", source.getNode(), | ||
| "Error information" |
Check warning
Code scanning / CodeQL
Consistent alert message Warning
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.
No, but it now has the same alert message as Java.
2a35af3
to
c660ea1
Compare
This gives us coverage of CWE-209.
It's a fairly direct port of the Python version of this query:
backtraceon exception variables, and calls toKernel#caller.One obvious idea for improving the query would be to define a sink for expressions inside
<%= ... %>tags in view templates. Do we have a succinct way of expressing that, e.g. a concept?