streamlit: Unexpected behaviour of showErrorDetails = false
Summary
When setting showErrorDetails to false, the stack is displayed.
Steps to reproduce
Code snippet:
main.py
import streamlit as st
import databases
import sqlalchemy
DATABASE_URL = 'postgresql://user:pwd@server.postgres.azurr.com:5432/dbname?sslmode=prefer'
database = databases.Database(DATABASE_URL)
engine = sqlalchemy.create_engine(
DATABASE_URL, pool_size=3, max_overflow=0
)
result_set = engine.execute('SELECT * FROM mytable')
config.toml
[client]
showErrorDetails = false
Expected behavior:
When setting showErrorDetails to false, I would expect no trace to be displayed, only a generic error message.
Actual behavior:
showErrorDetails = false This is the error message, followed by full trace:
sqlalchemy.exc.OperationalError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app). Traceback: File “C:\Users\greg_\dev\virtualenvs\hwq_front\lib\site-packages\streamlit\script_runner.py”, line 430, in run_script exec(code, module.dict) File “D:\HWQ\dev\HWQ_FRONT\bug.py”, line 11, in <module> result_set = engine.execute(‘SELECT * FROM mytable’) File “<string>”, line 2, in execute File "C:\Users\greg\dev\virtualenvs\hwq_front\lib\site-packages\sqlalchemy\util\deprecations.py", line 401, in warned return fn(*args, **kwargs) […]
showErrorDetails = true This is the error message, followed by full trace:
OperationalError: (psycopg2.OperationalError) could not connect to server: Connection timed out Is the server running on host “hwq-server.postgres.database.azure.com” (20.73.151.139) and accepting TCP/IP connections on port 5432? (Background on this error at: https://sqlalche.me/e/14/e3q8) Traceback: File “C:\Users\greg_\dev\virtualenvs\hwq_front\lib\site-packages\streamlit\script_runner.py”, line 430, in run_script exec(code, module.dict) File “D:\HWQ\dev\HWQ_FRONT\bug.py”, line 11, in <module> result_set = engine.execute(‘SELECT * FROM mytable’) File “<string>”, line 2, in execute File "C:\Users\greg\dev\virtualenvs\hwq_front\lib\site-packages\sqlalchemy\util\deprecations.py", line 401, in warned return fn(*args, **kwargs) […]
Is this a regression?
Can’t tell, using this feature for the first time.
Debug info
- Streamlit version: 1.6.0
- Python version: 3.9.7
- Using virtualenvwrapper with pip
- OS version: Windows 10
- Browser version: Chrome 99.0.4844.51
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 25
- Comments: 30
+1 to regard this as a bug and would be very desirable if fixed. For production apps this is a security risk.
Hey! We’re looking into this right now. Already wanted to do it a few months ago but it got moved due to some other projects and then I lost track of it, unfortunately.
My current plan is to fix this by
showErrorDetails = falseandshowErrorDetails = "traceback", which has the current behavior (i.e. hide the exception message but show the traceback).That way, we can keep showing the traceback on Community Cloud (which we find pretty useful for debugging but happy to hear other opinions!) and developers can turn it off completely when needed / if their app contains sensitive information directly in the code.
I still need to verify some things with the eng time but I’m hopeful we can get this done within the next few releases.
Hey all! Sorry for dropping this for quite a while. We looked into it two times in the past but always ran into some complications because Streamlit Community Cloud depends on this config option, so it’s not trivial to change. However, we found a good solution now.
We plan to switch over to the following literal values for
showErrorDetails:“full”- show everything“stacktrace”- show type and stacktrace, hide message (= replace it with the generic error message we have today)“type”- show type, hide message and stacktrace“none”- hide type, stacktrace, and messageWe will also slowly deprecate the
trueandfalsevalues since they are confusing. But this will be a very soft deprecation – we’ll probably just mark them as deprecated in the docs for now so devs stop using them. And it will be a very long time before we remove them, so we don’t break any existing production apps.Let me know if you have any feedback on this! We’re currently busy with other projects but plan to work on this in November/December.
It’s been 9 months since the last response, and this stops people from using Streamlit in organisations. Can a PM finally prioritise this piece of work? It’s more important than a new flashy component. There is no point in developing further a framework, if it creates critical security risks.
Yup. The current behavior is a big no-no for users in a corporate environment. It is one of the common security threats reported in security audits: “revealing too much information about the software being used and its errors”. Any updates on this one?
Will chime in here that it would be useful with this functionality to limit even what gets printed to the console in the stdout. (per my thread here on the streamlit forum). I noticed that database creds were getting printed in the exception. While showErrorDetails should theoretically hide the exception in the browser, the documentation seems to imply that the exception would still be printed in its entirety to the console. (Please correct me if I’m mistaken here.)
Also do support the original post on hiding the traceback as well as the exception. Especially with systems where our deployed applications are logged, sensitive data getting written out to stored logs (either in the exception or the traceback) in any way can become a huge no no. Would be great to be able to fully control the verbosity of the error messages on deployed applications.
Hello @vdonato @jrieke
Thanks for handling this. I don’t think displaying the trace it is expected behaviour. When the feature was added (see https://github.com/streamlit/streamlit/pull/2770), it clearly says “uncaught exceptions in a Streamlit app will result in a generic “Something went wrong!” warning in the browser, rather than the exception and its traceback”. So the traceback should be hidden in theory.
I agree that there is a mismatch between what
showErrorDetailsis supposed to do (per the docs / my initial understanding of it based on its name) and what it does.Per the docs:
# If set to False, an exception will result in a generic message being shown in the browser, and exceptions and tracebacks will be printed to the console only.As noted in this issue, the traceback does appear regardless of
showErrorDetails’s value.Thanks!
Hi @jrieke following up on this again. I am using
showErrorDetails = falsebut still see exception messages in the UI. Why is this the case, and what can we do to completely suppress errors/exceptions from being displayed in the UI?Here’s another option that will disable Streamlit’s “scriptrunner”
handle_uncaught_app_exception()method. I use Sentry to capture and log the exception when in production (with an environment variableDEBUGto toggle between displaying the error or logging to Sentry).This is implemented in 1.41, see #9909. The
client.showErrorDetailsconfig option now has the following 4 values. As indicated above, the True/False values are now deprecated.the bug persists as of 10/2024
When should we expect this update?
When trying to implement the above workaround, I am getting:
Anybody else encounter this? Am I looking in the wrong location within
sys.modules["streamlit.runtime.scriptrunner.script_runner"]?I am using
streamlitversion 1.37.1UPDATE 1: Apparently in version 1.37.x the location of
handle_uncaught_app_exceptionhas moved (back?) to thestreamlit.error_utilmodule. So this monkey-patching method works if you usescript_runner = sys.modules['streamlit.error_util'].UPDATE 2: In case anybody else is reading this with similar issues, I will paste my final code that is working on
streamlitversion 1.37.1 with Sentry. The important parts are that thehandle_uncaught_app_exceptionis located in thestreamlit.error_utilmodule, only the__code__attribute should be monkey patched, and thesentry_sdklibrary needs to be imported WITHIN the patched code so thatstreamlithas access to it. I have a condition where I check if sentry is initialized, and if it is not, then I print the full error (with stacktrace) to the application. This is because I am only initializing sentry in our dev/prod environments; but for local testing/development I want the full error visible.Hi @jrieke , any updates on this? It’s still broken in 1.35 and it’s a big issue for serious use cases.
same situation. option showErrorDetails doesn’t work as expected. Streamlit, version 1.33.0
+1, I agree with @senth1s and I think this is one of the issues that could block any serious team from using streamlit in a production environment.
Considering that this has been open for more than a year, can the team (maybe @jrieke ?) please provide an update on whether and when they plan to address such a big security risk (such as exposing service account credentials to the data warehouse)?
As Vincent stated above, this behavior was intentional. We wanted to give users a way to report where an error is coming from. But I can see that it could be problematic. We’re looking into it and will see if we want to change it!
@vdonato I wonder if you guys plan to address this. For public-facing apps, showing the trace is not desirable, and can be unsafe. I wish that there was an option to let the uncaught exceptions bubble up so that I could catch them and deal with them the way I want. For example, I could catch it and display a sad puppy’s picture instead of
st.exception. I guess a third option here, under which the exception doesn’t get handled, would be great.