8000 gh-135815: skip `netrc` security checks if `os.getuid` is missing by picnixz · Pull Request #135816 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135815: skip netrc security checks if os.getuid is missing #135816

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

Merged
merged 2 commits into from
Jun 22, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
avoid calling os.getuid() twice
  • Loading branch information
picnixz committed Jun 22, 2025
commit cbe216a1ee7ecc1af2a924340c49a87909c0ab47
5 changes: 3 additions & 2 deletions Lib/netrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ def _parse(self, file, fp, default_netrc):
def _security_check(self, fp, default_netrc, login):
if _can_security_check() and default_netrc and login != "anonymous":
prop = os.fstat(fp.fileno())
if prop.st_uid != os.getuid():
current_user_id = os.getuid()
if prop.st_uid != current_user_id:
fowner = _getpwuid(prop.st_uid)
user = _getpwuid(os.getuid())
user = _getpwuid(current_user_id)
raise NetrcParseError(
(f"~/.netrc file owner ({fowner}, {user}) does not match"
" current user"))
Comment on lines 165 to 166
Copy link
Member

Choose a reason for hiding this comment

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

The message looks weird. Would not be better to rewrite in in the following way?

                    (f"~/.netrc file owner ({fowner}) does not match"
                     f" current user ({user})"))

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll change it in a follow-up PR so that only unstable branches are affected.

Expand Down
Loading
0