Repository navigation
fix(deps): update dependency python-dotenv to v1.2.2 [security] - #6962
renovate[bot] wants to merge 1 commit into
Conversation
|
🪓 The generated code will be pushed at the end of the CI.Action triggered by commit Please do not push any generated code to this pull request. |
e68d183 to
c46a11b
Compare
c46a11b to
e0008e5
Compare
|
We still support Python 3.8, this update requires Python >=3.10. |
Renovate Ignore NotificationBecause you closed this PR without merging, Renovate will ignore this update ( If you accidentally closed this PR, or if you changed your mind: rename this PR to get a fresh replacement PR. |
This PR contains the following updates:
=1.0.1→=1.2.2== 1.0.1→==1.2.2Warning
Some dependencies could not be looked up. Check the Dependency Dashboard for more information.
python-dotenv: Symlink following in set_key allows arbitrary file overwrite via cross-device rename fallback
CVE-2026-28684 / GHSA-mf9w-mj56-hr94
More information
Details
Summary
set_key()andunset_key()in python-dotenv follow symbolic links when rewriting.envfiles, allowing a local attacker to overwrite arbitrary files via a crafted symlink when a cross-device rename fallback is triggered.Details
The
rewrite()context manager indotenv/main.pyis used by bothset_key()andunset_key()to safely modify.envfiles. It works by writing to a temporary file (created in the system's default temp directory, typically/tmp) and then usingshutil.move()to replace the original file.When the
.envpath is a symbolic link and the temp directory resides on a different filesystem than the target (a common configuration on Linux systems using tmpfs for/tmp), the following sequence occurs:shutil.move()first attemptsos.rename(), which fails with anOSErrorbecause atomic renames cannot cross device boundaries.shutil.move()falls back toshutil.copy2()followed byos.unlink().shutil.copy2()callsshutil.copyfile()withfollow_symlinks=Trueby default.An attacker who has write access to the directory containing a
.envfile can pre-place a symlink pointing to any file that the application process has write access to. When the application (or a privileged process such as a deploy script, Docker entrypoint, or CI pipeline) callsset_key()orunset_key(), the symlink target is overwritten with the new.envcontent.This vulnerability does not require a race condition and is fully deterministic once the preconditions are met.
Impact
The primary impacts are to integrity and availability:
.env-formatted content controlled by the attacker.set_key(), the attacker can leverage this to write to files beyond their own access level.The scope of impact depends on the application using python-dotenv and the privileges under which it runs.
Proof of Concept
The following script demonstrates the vulnerability. It requires
/tmpand the user's home directory to reside on different devices (common on systemd-based Linux systems with tmpfs).Expected output:
Remediation
The fix changes the
rewrite()context manager in the following ways:.envpath is a symlink,rewrite()now resolves it to the real path before proceeding, or (by default) operates on the symlink entry itself rather than the target.follow_symlinks: bool = Falseparameter is added toset_key()andunset_key()for users who explicitly need the old behavior..envfile (instead of the system temp directory), eliminating the cross-device rename condition entirely.os.replace()is used instead ofshutil.move(), providing atomic replacement without symlink-following fallback behavior.Users are advised to upgrade to the patched version as soon as it is available on PyPI.
Timeline
rewrite()Patches
Upgrade to v.1.2.2 or use the patch from https://github.com/theskumar/python-dotenv/commit/790c5c02991100aa1bf41ee5330aca75edc51311.patch
Severity
CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:N/I:H/A:HReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
Release Notes
theskumar/python-dotenv (python-dotenv)
v1.2.2Compare Source
Added
Changed
dotenv runcommand now forwards flags directly to the specified command by [@bbc2] in [#607]Fixed
set_keyandunset_keybehavior when interacting with symlinks by [@bbc2] in [790c5c0]Breaking Changes
dotenv.set_keyanddotenv.unset_keyused to follow symlinks in somesituations. This is no longer the case. For that behavior to be restored in
all cases,
follow_symlinks=Trueshould be used.In the CLI,
setandunsetused to follow symlinks in some situations. Thisis no longer the case.
dotenv.set_key,dotenv.unset_keyand the CLI commandssetandunsetused to reset the file mode of the modified .env file to
0o600in somesituations. This is no longer the case: The original mode of the file is now
preserved. Is the file needed to be created or wasn't a regular file, mode
0o600is used.v1.2.1Compare Source
pyproject.toml, removedsetup.cfg.envfrom FIFOs (Unix) by [@sidharth-sudhir] in [#586]v1.2.0Compare Source
buildandpyproject.tomlby [@EpicWink] in [#583]load_dotenv()usingPYTHON_DOTENV_DISABLEDenv var. by [@matthewfranglen] in [#569]v1.1.1Compare Source
Fixed
find_dotenvwork reliably on python 3.13 by [@theskumar] in [#563]v1.1.0Compare Source
Added
dotenv run, switch toexecvpefor better resource management and signal handling ([#523]) by [@eekstunt]Fixed
find_dotenvandload_dotenvnow correctly looks up at the current directory when running in debugger or pdb ([#553] by [@randomseed42])Misc
Configuration
📅 Schedule: (in timezone Europe/Paris)
🚦 Automerge: Enabled.
♻ Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about these updates again.
This PR was generated by Mend Renovate. View the repository job log.