Stack trace exposure Info

It seems that you are returning a stack trace to the user. We recommend that you use exception handling and send an error message to the user.

Detector ID
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1@app_flask.route('/noncompliant/<text>')
2def stack_trace_exposure_noncompliant(text):
3    try:
4        if text == 'error':
5            raise HTTPException
6        return jsonify({'data': 'some_data'}), 200
7    except HTTPException:
8        # Noncompliant: Stack trace is returned from api call.
9        return traceback.format_exc()

Compliant example

1@app_flask.route('/compliant/<text>')
2def stack_trace_exposure_compliant(text):
3    try:
4        if text == 'error':
5            raise HTTPException
6        return jsonify({'data': 'some_data'}), 200
7    except HTTPException:
8        # Compliant: Custom json response with message as cause of error.
9        return jsonify({'message': 'Internal error occurred!'}), 404