]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122117)
authorŁukasz Langa <lukasz@langa.pl>
Mon, 22 Jul 2024 11:41:23 +0000 (13:41 +0200)
committerGitHub <noreply@github.com>
Mon, 22 Jul 2024 11:41:23 +0000 (13:41 +0200)
Doc/library/asyncio.rst
Doc/using/cmdline.rst
Lib/asyncio/__main__.py
Misc/NEWS.d/next/Security/2024-07-22-13-14-38.gh-issue-121957.FYkcOt.rst [new file with mode: 0644]
Modules/main.c

index 184f981c1021aa3f27c6e2fbcffcb5dcb54f4174..1fb575d77f3e176d0c4a60b6fea7c243350bfd93 100644 (file)
@@ -56,8 +56,12 @@ Additionally, there are **low-level** APIs for
 * :ref:`bridge <asyncio-futures>` callback-based libraries and code
   with async/await syntax.
 
+.. include:: ../includes/wasm-notavail.rst
+
 .. _asyncio-cli:
 
+.. rubric:: asyncio REPL
+
 You can experiment with an ``asyncio`` concurrent context in the REPL:
 
 .. code-block:: pycon
@@ -70,7 +74,10 @@ You can experiment with an ``asyncio`` concurrent context in the REPL:
    >>> await asyncio.sleep(10, result='hello')
    'hello'
 
-.. include:: ../includes/wasm-notavail.rst
+.. audit-event:: cpython.run_stdin "" ""
+
+.. versionchanged:: 3.12.5 (also 3.11.10, 3.10.15, 3.9.20, and 3.8.20)
+   Emits audit events.
 
 .. We use the "rubric" directive here to avoid creating
    the "Reference" subsection in the TOC.
index 4c2798ab72b5f60924b2a270feec3af7d53e8a8c..9567c72d62bd1aa82476d6323299c5160407efe2 100644 (file)
@@ -720,6 +720,11 @@ conflict.
    This variable can also be modified by Python code using :data:`os.environ`
    to force inspect mode on program termination.
 
+   .. audit-event:: cpython.run_stdin "" ""
+
+   .. versionchanged:: 3.12.5 (also 3.11.10, 3.10.15, 3.9.20, and 3.8.20)
+      Emits audit events.
+
 
 .. envvar:: PYTHONUNBUFFERED
 
index c39a31d7b3df5ba39c4214390248c06cf4c66bb8..046558011513cb1666294f4cc6381ff620b6c520 100644 (file)
@@ -89,6 +89,8 @@ class REPLThread(threading.Thread):
 
 
 if __name__ == '__main__':
+    sys.audit("cpython.run_stdin")
+
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
 
diff --git a/Misc/NEWS.d/next/Security/2024-07-22-13-14-38.gh-issue-121957.FYkcOt.rst b/Misc/NEWS.d/next/Security/2024-07-22-13-14-38.gh-issue-121957.FYkcOt.rst
new file mode 100644 (file)
index 0000000..ff4614b
--- /dev/null
@@ -0,0 +1,3 @@
+Fixed missing audit events around interactive use of Python, now also
+properly firing for ``python -i``, as well as for ``python -m asyncio``. The
+event in question is ``cpython.run_stdin``.
index 1b189b456162e63303c0c7da81797799792fae02..b602272b78befd721401c576d9b1d26d2ec867a0 100644 (file)
@@ -540,6 +540,10 @@ pymain_repl(PyConfig *config, int *exitcode)
         return;
     }
 
+    if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
+        return;
+    }
+
     PyCompilerFlags cf = _PyCompilerFlags_INIT;
     int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
     *exitcode = (res != 0);