Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 984fb3a

Browse files
authored
Merge pull request #1043 from markshannon/python-fix-stack-trace-exposure
Python: fix stack trace exposure query.
2 parents db104ed + 38a5fb7 commit 984fb3a

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

python/ql/src/Security/CWE-209/StackTraceExposure.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ import semmle.python.security.Exceptions
1919
import semmle.python.web.HttpResponse
2020

2121
from TaintedPathSource src, TaintedPathSink sink
22-
where src.flowsTo(sink)
22+
where src.flowsTo(sink) and src.getSource() instanceof ErrorInfoSource
2323
select sink.getSink(), src, sink, "$@ may be exposed to an external user", src.getSource(), "Error information"

python/ql/src/semmle/python/security/Exceptions.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class ExceptionInfo extends StringKind {
3131

3232
}
3333

34+
/** A class representing sources of information about
35+
* execution state exposed in tracebacks and the like.
36+
*/
37+
abstract class ErrorInfoSource extends TaintSource {}
3438

3539
/**
3640
* This kind represents exceptions themselves.
@@ -56,7 +60,7 @@ class ExceptionKind extends TaintKind {
5660
* A source of exception objects, either explicitly created, or captured by an
5761
* `except` statement.
5862
*/
59-
class ExceptionSource extends TaintSource {
63+
class ExceptionSource extends ErrorInfoSource {
6064

6165
ExceptionSource() {
6266
exists(ClassObject cls |
@@ -91,7 +95,7 @@ class ExceptionInfoSequence extends SequenceKind {
9195
* Represents calls to functions in the `traceback` module that return
9296
* sequences of exception information.
9397
*/
94-
class CallToTracebackFunction extends TaintSource {
98+
class CallToTracebackFunction extends ErrorInfoSource {
9599

96100
CallToTracebackFunction() {
97101
exists(string name |
@@ -120,7 +124,7 @@ class CallToTracebackFunction extends TaintSource {
120124
* Represents calls to functions in the `traceback` module that return a single
121125
* string of information about an exception.
122126
*/
123-
class FormattedTracebackSource extends TaintSource {
127+
class FormattedTracebackSource extends ErrorInfoSource {
124128

125129
FormattedTracebackSource() {
126130
this = traceback_function("format_exc").getACall()

python/ql/test/query-tests/Security/CWE-209/test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Flask
1+
from flask import Flask, request, make_response
22
app = Flask(__name__)
33

44

@@ -35,3 +35,8 @@ def server_bad_flow():
3535

3636
def format_error(msg):
3737
return "[ERROR] " + msg
38+
39+
#Unrelated error
40+
@app.route('/maybe_xss')
41+
def maybe_xss():
42+
return make_response(request.args.get('name', ''))

0 commit comments

Comments
 (0)