Skip to content

Commit 042a191

Browse files
fix(security): Don't interpolate values in orgs' sentry_config.ini (#176)
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
1 parent 80bb196 commit 042a191

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎src/sentry_config.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ def _fetch_config(org: str, token: str | None) -> OrgConfig:
8181
file_contents = base64.b64decode(meta["content"]).decode()
8282

8383
# - Read ini file and assertions
84-
cp = ConfigParser()
84+
# Anyone can install the app and write this file. Interpolation expands nested
85+
# `%(key)s` references without a size limit, so a few hundred bytes can hold the
86+
# thread (and memory) for hours. No value needs it.
87+
cp = ConfigParser(interpolation=None)
8588
cp.read_string(file_contents)
8689
section = "sentry-github-actions-app"
8790
# e.g. `commit_workflows = backend.yml, frontend.yml`

‎tests/test_sentry_config_file.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,15 @@ def test_commit_workflows_default_to_every_workflow() -> None:
137137
assert fetch_config_for_github_org(
138138
org, token, installation_id
139139
).commit_workflows == (frozenset())
140+
141+
142+
@responses.activate
143+
def test_values_are_not_interpolated() -> None:
144+
# Each level doubles the value; with more references per level, a few hundred
145+
# bytes would expand to gigabytes
146+
nested = "".join(f"v{i} = %(v{i - 1})s%(v{i - 1})s\n" for i in range(1, 10))
147+
responses.get(
148+
org_api_url,
149+
json=sentry_config_response("%(v9)s", f"v0 = x\n{nested}"),
150+
)
151+
assert fetch_dsn_for_github_org(org, token, installation_id) == "%(v9)s"

0 commit comments

Comments
 (0)