Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-41316: Make tarfile follow specs for FNAME #21511

Merged
merged 6 commits into from
Sep 7, 2020
Merged

bpo-41316: Make tarfile follow specs for FNAME #21511

merged 6 commits into from
Sep 7, 2020

Conversation

ArtemSBulgakov
Copy link
Contributor

@ArtemSBulgakov ArtemSBulgakov commented Jul 16, 2020

tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.

https://bugs.python.org/issue41316

Automerge-Triggered-By: @jaraco

@ofek
Copy link
Sponsor Contributor

ofek commented Jul 16, 2020

Great find!

Lib/tarfile.py Show resolved Hide resolved
@ArtemSBulgakov
Copy link
Contributor Author

@ethanfurman Could you please review changes?

ArtemSBulgakov and others added 3 commits July 28, 2020 17:00
tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.
@ArtemSBulgakov
Copy link
Contributor Author

Anyone?

Lib/tarfile.py Outdated Show resolved Hide resolved
Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to capture the expected behavior?

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@jaraco
Copy link
Member

jaraco commented Sep 7, 2020

In 3948880 , I added a failing test and in 0bbaa1c, merged it with the change, demonstrating the fix.

@serhiy-storchaka serhiy-storchaka added needs backport to 3.8 only security fixes needs backport to 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Sep 7, 2020
@miss-islington
Copy link
Contributor

@ArtemSBulgakov: Status check is done, and it's a failure ❌ .

@miss-islington
Copy link
Contributor

@ArtemSBulgakov: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit 22748a8 into python:master Sep 7, 2020
@miss-islington
Copy link
Contributor

Thanks @ArtemSBulgakov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 7, 2020
tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.

Automerge-Triggered-By: @jaraco
(cherry picked from commit 22748a8)

Co-authored-by: Artem Bulgakov <ArtemSBulgakov@ya.ru>
@bedevere-bot
Copy link

GH-22140 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Sep 7, 2020
@bedevere-bot
Copy link

GH-22141 is a backport of this pull request to the 3.8 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.8 only security fixes label Sep 7, 2020
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 7, 2020
tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.

Automerge-Triggered-By: @jaraco
(cherry picked from commit 22748a8)

Co-authored-by: Artem Bulgakov <ArtemSBulgakov@ya.ru>
shihai1991 added a commit to shihai1991/cpython that referenced this pull request Sep 10, 2020
* origin/master: (1373 commits)
  bpo-1635741: Port mashal module to multi-phase init (python#22149)
  bpo-1635741: Port _string module to multi-phase init (pythonGH-22148)
  bpo-1635741: Convert _sha256 types to heap types (pythonGH-22134)
  bpo-1635741: Port the termios to multi-phase init (PEP 489) (pythonGH-22139)
  bpo-41732: add iterator to memoryview (pythonGH-22119)
  bpo-40744: Drop support for SQLite pre 3.7.3 (pythonGH-20909)
  bpo-41316: Make tarfile follow specs for FNAME (pythonGH-21511)
  bpo-41720: Add "return NotImplemented" in turtle.Vec2D.__rmul__(). (pythonGH-22092)
  bpo-1635741 port _curses_panel to multi-phase init (PEP 489) (pythonGH-21986)
  bpo-1635741: Port _overlapped module to multi-phase init (pythonGH-22051)
  bpo-1635741: Port _opcode module to multi-phase init (PEP 489) (pythonGH-22050)
  bpo-1635741 port zlib module to multi-phase init (pythonGH-21995)
  [doc] Add link to Generic in typing (pythonGH-22125)
  bpo-41513: Expand comments and add references for a better understanding (pythonGH-22123)
  bpo-1635741: Port _sha1, _sha512, _md5 to multiphase init (pythonGH-21818)
  closes bpo-41723: Fix an error in the py_compile documentation. (pythonGH-22110)
  [doc] Fix padding in some typing definitions (pythonGH-22114)
  Fix documented Python version for venv --upgrade-deps (pythonGH-22113)
  bpo-40318: Migrate to SQLite3 trace v2 API (pythonGH-19581)
  bpo-41687: Fix sendfile implementation to work with Solaris (python#22040)
  ...
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.

Automerge-Triggered-By: @jaraco
miss-islington added a commit that referenced this pull request Oct 21, 2020
tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.

Automerge-Triggered-By: @jaraco
(cherry picked from commit 22748a8)

Co-authored-by: Artem Bulgakov <ArtemSBulgakov@ya.ru>
miss-islington added a commit that referenced this pull request Oct 21, 2020
tarfile writes full path to FNAME field of GZIP format instead of just basename if user specified absolute path. Some archive viewers may process file incorrectly. Also it creates security issue because anyone can know structure of directories on system and know username or other personal information.

RFC1952 says about FNAME:
This is the original name of the file being compressed, with any directory components removed.

So tarfile must remove directory names from FNAME and write only basename of file.

Automerge-Triggered-By: @jaraco
(cherry picked from commit 22748a8)

Co-authored-by: Artem Bulgakov <ArtemSBulgakov@ya.ru>
@kodonnell
Copy link

I hit this in 3.7 - any reason it wasn't backported? Without knowing much about @miss-islington it looks like this just needs a needs backport to 3.7 label as @serhiy-storchaka did for 3.8/3.9. If there's anything else, happy to help.

@miss-islington
Copy link
Contributor

Thanks @ArtemSBulgakov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @ArtemSBulgakov, I had trouble checking out the 3.7 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 22748a83d927d3da1beaed771be30887c42b2500 3.7

@miss-islington miss-islington self-assigned this Dec 6, 2021
@ethanfurman
Copy link
Member

ethanfurman commented Dec 6, 2021

Python 3.7 is now in security-maintenance mode, so no new binary releases. You'll have to build the updated Python yourself.

I'll try to get to the cherrypick this week if nobody else beats me to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error type-security A security issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants