Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,14 @@ concurrent.futures
buffer.
(Contributed by Enzo Bonnal and Josh Rosenberg in :gh:`74028`.)

configparser
------------

* Security fix: will no longer write config files it cannot read. Attempting
to :meth:`configparser.ConfigParser.write` keys containing delimiters or
beginning with the section header pattern will raise a
:class:`configparser.InvalidWriteError`.
(Contributed by Jacob Lincoln in :gh:`129270`)

contextvars
-----------
Expand Down
11 changes: 7 additions & 4 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,11 +1218,14 @@ def _convert_to_boolean(self, value):

def _validate_key_contents(self, key):
"""Raises an InvalidWriteError for any keys containing
delimiters or that match the section header pattern"""
delimiters or that begins with the section header pattern"""
if re.match(self.SECTCRE, key):
raise InvalidWriteError("Cannot write keys matching section pattern")
if any(delim in key for delim in self._delimiters):
raise InvalidWriteError("Cannot write key that contains delimiters")
raise InvalidWriteError(
f"Cannot write key {key}; begins with section pattern")
for delim in self._delimiters:
if delim in key:
raise InvalidWriteError(
f"Cannot write key {key}; contains delimiter {delim}")

def _validate_value_types(self, *, section="", option="", value=""):
"""Raises a TypeError for illegal non-string values.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`configparser`'s error message when attempting to write an invalid key is now more helpful.
Loading