René's URL Explorer Experiment


Title: _remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578) · Issue #149474 · python/cpython · GitHub

Open Graph Title: _remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578) · Issue #149474 · python/cpython

X Title: _remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578) · Issue #149474 · python/cpython

Description: _remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578) Affects only main / 3.15-dev — not a PSRT case Per python.org/dev/security/, the PSRT does not accept reports that only affect pre-release versions. The _remote_de...

Open Graph Description: _remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578) Affects only main / 3.15-dev — not a PSRT case Per python.org/dev/security/, the PSRT does not accept reports that only aff...

X Description: _remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578) Affects only main / 3.15-dev — not a PSRT case Per python.org/dev/security/, the PSRT does not accept reports that only aff...

Opengraph URL: https://github.com/python/cpython/issues/149474

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578)","articleBody":"# `_remote_debugging.BinaryWriter()` bypasses file-open audit hooks (PEP 578)\n\n## Affects only `main` / 3.15-dev — not a PSRT case\n\nPer [python.org/dev/security/](https://www.python.org/dev/security/), the PSRT does not accept reports that only affect pre-release versions. The `_remote_debugging.BinaryWriter` API is new in 3.15-dev and does not exist on any supported branch, so this is a regular bug report rather than a private security advisory.\n\n| Branch | `Modules/_remote_debugging/binary_io_writer.c` exists? | Affected? |\n|---|---|---|\n| main (3.15-dev) | yes | **yes** |\n| 3.14, 3.13, 3.12, 3.11, 3.10 | no | no |\n\n(The whole `_remote_debugging.BinaryWriter` API was added in 3.15-dev as part of the new `profiling.sampling` binary-replay workflow.)\n\n## What's wrong\n\n`Modules/_remote_debugging/binary_io_writer.c::binary_writer_create` calls `fopen(filename, \"wb\")` to open the output file, but does **not** fire `PySys_Audit(\"open\", \"sCi\", filename, 'w', 0)` first. The canonical pattern in cpython is to fire the audit hook before `fopen`:\n\n- `Modules/readline.c:347` — fires `PySys_Audit(\"open\", \"sCi\", filename, 'w', 0)` before `fopen`.\n- `Modules/_io/fileio.c::_io_FileIO___init___impl` — fires `PySys_Audit(\"open\", \"OOi\", ...)` before opening the FD.\n\n`binary_writer_create` follows neither precedent. An operator's `open` audit-hook does not fire when `_remote_debugging.BinaryWriter(target)` writes to `target`, even though the operator's same hook DOES fire on `builtins.open(target, \"w\")` and `_io.FileIO(target, \"w\")`.\n\n## Reproducer\n\nOn a fresh `main` checkout (a debug build is fine, e.g. `./configure --with-pydebug && make -j8`):\n\n```python\nimport os, sys, _remote_debugging\n\nevents = []\ndef hook(event, args):\n    if event == \"open\":\n        events.append({\"path\": str(args[0]) if args else None,\n                       \"mode\": str(args[1]) if len(args) > 1 else None})\n\nTARGET = \"/tmp/poc-binary-writer.prof\"\nCONTROL = \"/tmp/poc-builtins-open.txt\"\nfor p in (TARGET, CONTROL):\n    if os.path.exists(p): os.unlink(p)\n\nsys.addaudithook(hook)\n\n# Negative control — should fire the audit hook (built-in `open`):\nwith open(CONTROL, \"w\") as f:\n    f.write(\"control\\n\")\n\n# Target — should fire the audit hook per PEP 578, currently does NOT:\nCOMP_NONE = getattr(_remote_debugging, \"COMPRESSION_NONE\", 0)\nw = _remote_debugging.BinaryWriter(TARGET, sample_interval_us=1000,\n                                    compression=COMP_NONE, start_time_us=0)\nw.close()\n\ncontrol_fired = any(e[\"path\"] == CONTROL for e in events)\ntarget_fired = any(e[\"path\"] == TARGET for e in events)\nprint(f\"control_fired={control_fired} target_fired={target_fired}\")\n# Expected (post-fix): control_fired=True target_fired=True\n# Actual on baseline:  control_fired=True target_fired=False\n\nfor p in (TARGET, CONTROL):\n    if os.path.exists(p): os.unlink(p)\n```\n\n## Suggested fix\n\nInsert the canonical `PySys_Audit` call before the `fopen`. Pattern matches `Modules/readline.c:347` verbatim.\n\n```diff\ndiff --git a/Modules/_remote_debugging/binary_io_writer.c b/Modules/_remote_debugging/binary_io_writer.c\n@@ -802,6 +802,10 @@ binary_writer_create(const char *filename, uint64_t sample_interval_us, int comp\n         }\n     }\n\n+    if (PySys_Audit(\"open\", \"sCi\", filename, 'w', 0) \u003c 0) {\n+        goto error;\n+    }\n+\n     writer->fp = fopen(filename, \"wb\");\n     if (!writer->fp) {\n         PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);\n```\n\n## Empirical verification\n\nPatched against fork SHA `836fbdaa` (close to upstream `main`):\n\n| Run | `control_fired` (`builtins.open(CONTROL)`) | `target_fired` (`BinaryWriter(TARGET)`) |\n|---|---|---|\n| Baseline | true | **false** (vuln) |\n| Patched | true | true |\n\nNegative control fires correctly on both trees; mutation-confirmed sound (reverting just the patched line returns `target_fired=false`).\n\nPoC soundness verdict: `sound`.\n\n## Severity\n\nPEP 578 contract violation (audit-hook visibility gap on a documented profiling tool's file-write path), not RCE. An attacker who can invoke `_remote_debugging.BinaryWriter` writes to arbitrary paths without operator hook visibility. Recommend `topic-security` / `topic-audit-hooks` triage labels.\n\n## Notes for triage\n\n- 4-line idiomatic insertion that matches the canonical PEP 578 implementation pattern in cpython (`Modules/readline.c:347`).\n- No public-API surface change: `_remote_debugging.BinaryWriter()` constructor signature, return type, and exception types are unchanged.\n- Operators who reject the event via hook (raise an exception) will now see `BinaryWriter()` raise — aligns with all other audited file-open call sites.\n\nThis issue is part of a small set of PEP 578 audit-hook bypass findings observed on `main`; a sibling issue covers `posix._clearenv()` / `os.environ.clear()` (file `Modules/posixmodule.c`).\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-149524\n* gh-149586\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/omkhar","@type":"Person","name":"omkhar"},"datePublished":"2026-05-06T21:47:56Z","url":"https://github.com/python/cpython/issues/149474"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:303417c3-cb33-532a-87c0-641baba89855
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id94AE:1CCECA:117813D:174F4C0:6B01F345
html-safe-nonce35accff756e77e4a6e5dbdec5765d43304af7001d7ee0e9c5e86dce48dae4979
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEFFOjFDQ0VDQToxMTc4MTNEOjE3NEY0QzA6NkIwMUYzNDUiLCJ2aXNpdG9yX2lkIjoiNDc4NzM3MjE4NTc0NjUzNTIzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf5074b860307b21536cf4bdfccd39ca6c544e3e03d7d53eff728101625e92fab
hovercard-subject-tagissue:4394657747
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/149474/issue_layout
twitter:imagehttps://opengraph.githubassets.com/70ef64726669ef7bccacc2e11f90a59e4dcf47983cf434438de5ae39681cee7d/python/cpython/issues/149474
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/70ef64726669ef7bccacc2e11f90a59e4dcf47983cf434438de5ae39681cee7d/python/cpython/issues/149474
og:image:alt_remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578) Affects only main / 3.15-dev — not a PSRT case Per python.org/dev/security/, the PSRT does not accept reports that only aff...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameomkhar
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/149474#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149474
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F149474
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/149474
Reloadhttps://github.com/python/cpython/issues/149474
Reloadhttps://github.com/python/cpython/issues/149474
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/149474
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/149474
#149524https://github.com/python/cpython/pull/149524
_remote_debugging.BinaryWriter() bypasses file-open audit hooks (PEP 578)https://github.com/python/cpython/issues/149474#top
#149524https://github.com/python/cpython/pull/149524
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/omkhar
omkharhttps://github.com/omkhar
on May 6, 2026https://github.com/python/cpython/issues/149474#issue-4394657747
python.org/dev/security/https://www.python.org/dev/security/
gh-149474: use Py_fopen in Binary{Reader,Writer} for audit hook and path-like support #149524https://github.com/python/cpython/pull/149524
[3.15] gh-149474: use Py_fopen in Binary{Reader,Writer} for audit hook and path-like support (GH-149524) #149586https://github.com/python/cpython/pull/149586
picnixzhttps://github.com/picnixz
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on May 6, 2026https://github.com/python/cpython/issues/149474#event-25237688434
picnixzhttps://github.com/picnixz
on May 6, 2026https://github.com/python/cpython/issues/149474#event-25237957329
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on May 6, 2026https://github.com/python/cpython/issues/149474#issuecomment-4392631294
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on May 6, 2026https://github.com/python/cpython/issues/149474#issuecomment-4392848630
cpython/Modules/_remote_debugging/binary_io_reader.chttps://github.com/python/cpython/blob/2b7c28a4406da1b26dd0ebd38aa7371bed873ce4/Modules/_remote_debugging/binary_io_reader.c#L383
2b7c28ahttps://github.com/python/cpython/commit/2b7c28a4406da1b26dd0ebd38aa7371bed873ce4
cpython/Modules/_remote_debugging/binary_io_reader.chttps://github.com/python/cpython/blob/2b7c28a4406da1b26dd0ebd38aa7371bed873ce4/Modules/_remote_debugging/binary_io_reader.c#L441
2b7c28ahttps://github.com/python/cpython/commit/2b7c28a4406da1b26dd0ebd38aa7371bed873ce4
pablogsalhttps://github.com/pablogsal
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#149524https://github.com/python/cpython/pull/149524
on May 9, 2026https://github.com/python/cpython/issues/149474#event-25327163375
pablogsalhttps://github.com/pablogsal
on May 9, 2026https://github.com/python/cpython/issues/149474#event-25327163401
gh-149474: use `Py_fopen` in `Binary{Reader,Writer}` for audit hook a…https://github.com/python/cpython/commit/354ef336e4cd48cf0c02bc9a0c642adf5d543184
gh-149474https://github.com/python/cpython/issues/149474
354ef33https://github.com/python/cpython/commit/354ef336e4cd48cf0c02bc9a0c642adf5d543184
[3.15] gh-149474: use `Py_fopen` in `Binary{Reader,Writer}` for audit…https://github.com/python/cpython/commit/2b1eed460d598a30a5eab63f5f1f4d8ac8e43468
gh-149474https://github.com/python/cpython/issues/149474
2b1eed4https://github.com/python/cpython/commit/2b1eed460d598a30a5eab63f5f1f4d8ac8e43468
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/149474
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/149474
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.