From b46bdd85a86ee28c7c0fff690506484ef07dffff Mon Sep 17 00:00:00 2001 From: sysy <2772196789@qq.com> Date: Mon, 17 Aug 2026 20:39:44 -0400 Subject: [PATCH] Fix path traversal via symlink in embedded_get() os.path.abspath() is purely lexical and does not resolve symbolic links. A crafted PDF with an embedded filename like "link/pwned.txt", where "link" is a symlink pointing outside cwd, passes the abspath guard but open() follows the symlink at write time. Replace abspath() with realpath() so the containment check resolves the full symlink chain before comparing against the working directory. --- src/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 398da7b73..73b6ac16d 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -356,8 +356,8 @@ def embedded_get(args): if not args.unsafe and not args.output: if os.path.exists(filename): sys.exit(f'refusing to overwrite existing file with stored name: {filename}') - filename_abs = os.path.abspath(filename) - if not filename_abs.startswith(os.getcwd() + os.sep): + filename_real = os.path.realpath(filename) + if not filename_real.startswith(os.path.realpath(os.getcwd()) + os.sep): sys.exit(f'refusing to write stored name outside current directory: {filename}') with open(filename, "wb") as output: output.write(stream)