app: the STREAMLIT_* environment variable translation can crash the app at startup #24

Open
opened 2026-10-06 13:48:24 +00:00 by ffrauenberger · 1 comment
Owner

Severity: low (only some environment values trigger it)

Where

  • app/__main__.py:7-44

Problem

The entry point translates STREAMLIT_* environment variables into Streamlit config keys:

  • env_to_config_key assumes at least two _-separated parts after the prefix. A variable such as STREAMLIT_FOO gives option = [], and option[0] raises IndexError outside the try, so the service fails to start because of an unrelated environment variable.
  • env_key[10:] hard-codes the length of "STREAMLIT_" although prefix is a parameter.
  • Nested sections cannot be expressed: theme.light.sidebar.font becomes theme.lightSidebarFont. Acronyms other than enableCORS are converted to camelCase naively (server.enableXsrfProtection only works by chance).
  • parse_env_value handles only bools and non-negative ints; floats and negative numbers stay strings, which config.set_option may reject.
  • Errors are printed instead of logged.

Steps to reproduce

  1. Set STREAMLIT_FOO=1
  2. Start the app via python -m app

Expected behavior

Unknown or malformed variables are ignored (with a logged warning), and the app starts.

Actual behavior

The app crashes at startup with IndexError.

Fix

Use an explicit allow-list mapping from environment variables to config keys, or rely on Streamlit's own --server.* CLI flags / config.toml. Do the parsing inside the try and log errors.


from issues/BUG-024-streamlit-env-var-translation-is-fragile.md (code analysis of commit 6bcc646, 2026-10-03)

**Severity:** low (only some environment values trigger it) ## Where - `app/__main__.py:7-44` ## Problem The entry point translates `STREAMLIT_*` environment variables into Streamlit config keys: - `env_to_config_key` assumes at least two `_`-separated parts after the prefix. A variable such as `STREAMLIT_FOO` gives `option = []`, and `option[0]` raises `IndexError` **outside** the `try`, so the service fails to start because of an unrelated environment variable. - `env_key[10:]` hard-codes the length of `"STREAMLIT_"` although `prefix` is a parameter. - Nested sections cannot be expressed: `theme.light.sidebar.font` becomes `theme.lightSidebarFont`. Acronyms other than `enableCORS` are converted to camelCase naively (`server.enableXsrfProtection` only works by chance). - `parse_env_value` handles only bools and non-negative ints; floats and negative numbers stay strings, which `config.set_option` may reject. - Errors are `print`ed instead of logged. ### Steps to reproduce 1. Set `STREAMLIT_FOO=1` 2. Start the app via `python -m app` ### Expected behavior Unknown or malformed variables are ignored (with a logged warning), and the app starts. ### Actual behavior The app crashes at startup with `IndexError`. ## Fix Use an explicit allow-list mapping from environment variables to config keys, or rely on Streamlit's own `--server.*` CLI flags / `config.toml`. Do the parsing inside the `try` and log errors. --- from `issues/BUG-024-streamlit-env-var-translation-is-fragile.md` (code analysis of commit 6bcc646, 2026-10-03)
Author
Owner

Reviewed by Codex (GPT-6) against origin/main 6bcc646eb464.

Review: partially correct.

The startup crash for STREAMLIT_FOO and limited value parsing are supported. Two textual details need correction: prefix is a parameter of apply_streamlit_env, not env_to_config_key; the latter always strips ten characters. Also, server.enableXsrfProtection is the correct Streamlit 1.58 configuration spelling, not an accidental casing success. The reviewed Nix environment accepts it and returns its value. Keep the malformed-variable, nested-section and custom-prefix findings without implying that this particular XSRF mapping is broken.

Code references: app/main.py:18, app/main.py:32.

Reviewed by **Codex (GPT-6)** against origin/main [`6bcc646eb464`](https://code.swisdata.eu/ffrauenberger/ProcessIntel/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4). **Review: partially correct.** The startup crash for `STREAMLIT_FOO` and limited value parsing are supported. Two textual details need correction: `prefix` is a parameter of **`apply_streamlit_env`**, not `env_to_config_key`; the latter always strips ten characters. Also, `server.enableXsrfProtection` is the **correct** Streamlit 1.58 configuration spelling, not an accidental casing success. The reviewed Nix environment accepts it and returns its value. Keep the malformed-variable, nested-section and custom-prefix findings without implying that this particular XSRF mapping is broken. Code references: [app/__main__.py:18](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/__main__.py#L18), [app/__main__.py:32](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/__main__.py#L32).
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ffrauenberger/ProcessIntel#24
No description provided.