Skip to content

Commit a79f847

Browse files
authored
PEP 768: Expand the security considerations section (#4173)
1 parent cbf8efb commit a79f847

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

peps/pep-0768.rst

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,30 @@ An example usage of the API would look like:
294294
except Exception as e:
295295
print(f"Failed to execute code: {e}")
296296
297+
Configuration API
298+
-----------------
299+
300+
To allow redistributors, system administrators, or users to disable this
301+
mechanism, several methods will be provided to control the behavior of the
302+
interpreter:
303+
304+
A new ``PYTHON_DISABLE_REMOTE_DEBUG`` environment variable will
305+
be provided to control the behaviour at runtime. If set to any value (including an empty string), the
306+
interpreter will ignore any attempts to attach a debugger using this mechanism.
307+
308+
This environment variable will be added together with a new ``-X disable-remote-debug``
309+
flag to the Python interpreter to allow users to disable this feature at runtime.
310+
311+
Additionally a new ``--without-remote-debug`` flag will be added to the
312+
``configure`` script to allow redistributors to build Python without support for
313+
remote debugging if they so desire.
314+
315+
A new flag indicating the status of remote debugging will be made available via
316+
the debug offsets so tools can query if a remote process has disabled the
317+
feature. This way, tools can offer a useful error message explaining why they
318+
won't work, instead of believing that they have attached and then never having
319+
their script run.
320+
297321

298322
Backwards Compatibility
299323
=======================
@@ -306,10 +330,14 @@ Security Implications
306330
=====================
307331

308332
This interface does not introduce new security concerns as it is only usable by
309-
processes that can already write to arbitrary memory within your process and
333+
processes that can already write to arbitrary memory within a given process and
310334
execute arbitrary code on the machine (in order to create the file containing
311335
the Python code to be executed).
312336

337+
Furthermore, the execution of the code is gated by the interpreter's
338+
audit hooks, which can be used to monitor or prevent the execution of the code
339+
in sensitive environments.
340+
313341
Existing operating system security mechanisms are effective for guarding
314342
against attackers gaining arbitrary memory write access. Although the PEP
315343
doesn't specify how memory should be written to the target process, in practice
@@ -368,6 +396,35 @@ proposed interface.
368396
By maintaining compatibility with existing security frameworks, this design
369397
ensures that adopting the new interface requires no changes to established.
370398

399+
Security scenarios
400+
------------------
401+
402+
* For an external attacker, the ability to write to arbitrary memory in a
403+
process is already a severe security issue. This interface does not introduce
404+
any new attack surface, as the attacker would already have the ability to
405+
execute arbitrary code in the process. This interface behaves in exactly
406+
the same way as existing debuggers, and does not introduce any new additional
407+
security risks.
408+
* For an attacker who has gained arbitrary memory write access to a process but
409+
not arbitrary code execution, this interface does not allow them to escalate.
410+
The ability to calculate and write to specific memory locations is required,
411+
which is not available without compromising other machine resources that
412+
are external to the Python process.
413+
414+
Additionally, the fact that the code to be executed is gated by the interpreter's
415+
audit hooks means that the execution of the code can be monitored and controlled
416+
by system administrators. This means that even if the attacker has compromised the
417+
application **and the filesystem**, leveraging this interface for malicious
418+
purposes provides a very risky proposition for an attacker, as they risk
419+
exposing their actions to system administrators that could not only detect the
420+
attack but also take action to prevent it.
421+
422+
Finally, is important to note that if an attacker has arbitrary memory write
423+
access to a process and has compromised the filesystem, they can already
424+
escalate to arbitrary code execution using other existing mechanisms, so this
425+
interface does not introduce any new risks in this scenario.
426+
427+
371428
How to Teach This
372429
=================
373430

0 commit comments

Comments
 (0)