-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest.py
More file actions
70 lines (57 loc) · 1.41 KB
/
test.py
File metadata and controls
70 lines (57 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask import Flask, request, make_response, jsonify
app = Flask(__name__)
import traceback
def do_computation():
raise Exception("Secret info")
# BAD
@app.route('/bad')
def server_bad():
try:
do_computation()
except Exception:
return traceback.format_exc() #$ exceptionInfo
# BAD
@app.route('/bad/direct')
def server_bad_direct():
try:
do_computation()
except Exception as e: #$ exceptionInfo
return e
# BAD
@app.route('/bad/traceback')
def server_bad_traceback():
try:
do_computation()
except Exception as e: #$ exceptionInfo
return e.__traceback__
# GOOD
@app.route('/good')
def server_good():
try:
do_computation()
except Exception:
log(traceback.format_exc()) #$ exceptionInfo
return "An internal error has occurred!"
#BAD
@app.route('/bad/with-flow')
def server_bad_flow():
try:
do_computation()
except Exception:
err = traceback.format_exc() #$ exceptionInfo
return format_error(err)
def format_error(msg):
return "[ERROR] " + msg
#Unrelated error
@app.route('/maybe_xss')
def maybe_xss():
return make_response(request.args.get('name', ''))
# BAD
@app.route('/bad/jsonify')
def bad_jsonify():
try:
do_computation()
except Exception as e: # $ exceptionInfo
return jsonify({"error": str(e)})
if __name__ == "__main__":
app.run(debug=True)