refactor: remove legacy importer and exporter#5153
Open
chrislongros wants to merge 3 commits into
Open
Conversation
os.path.commonprefix matches characters rather than path components. Use startswith(dir + os.sep) instead to prevent path traversal.
Documentation build overview
32 files changed ·
|
The legacy import option was removed in ankitects#3536. Remove the dead code associated with the legacy importer.
chrislongros
force-pushed
the
fix-apkg-path-traversal
branch
from
July 17, 2026 16:23
74052c5 to
e41f234
Compare
Member
|
We might want to clean up legacy_import_export() as well? It's still referenced by the browser. |
Dead code since ankitects#3536 made legacy_import_export() always return False. Also fix the export dialog's string-based commonprefix path check.
Comment on lines
-129
to
132
| NOTE: Updates to the import/export code are expected in the coming | ||
| months, and this hook may be replaced with another solution at that | ||
| time. Tracked on https://github.com/ankitects/anki/issues/1018 | ||
| </Warning> | ||
|
|
Contributor
There was a problem hiding this comment.
Is issue #1018 still relevant or can it be closed by this PR?
Member
There was a problem hiding this comment.
It's still relevant for future work on built-in collaboration features.
Contributor
Author
I submitted a new follow up commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue (required)
Closes #5167
Motivation
The
.apkgmedia usesos.path.commonprefix, which compares characters, not path components. A media filename resolving to a sibling directory that shares the media folder's name prefix passes the check, so a malicious.apkgcan write outsidecollection.media(path traversal / arbitrary file write).A second commit removes the legacy importer entirely. The legacy import option was removed in #3536, leaving pylib/anki/importing, qt/aqt/importing.py and their dialog forms unreachable.
The third commit removes the legacy exporter and adds a realpath check instead of the commonprefix.
Steps to reproduce
.apkgwhose media maps a file into a sibling directory whose name begins with the media folder's name.collection.media. After: "Invalid file".Testing performed
Tested by importing .apkg and .csv decks via File > Import on the main branch and on the PR branch.
Cards import completes without problems.
Also tested a deck and collection export with support to older Anki versions enabled. It works fine.