Skip to content

Issue 126: redact passwords in repr#127

Merged
bbayles merged 1 commit intomainfrom
repr-passwords-gh
Feb 25, 2026
Merged

Issue 126: redact passwords in repr#127
bbayles merged 1 commit intomainfrom
repr-passwords-gh

Conversation

@bbayles
Copy link
Collaborator

@bbayles bbayles commented Feb 25, 2026

This PR updates the __repr__ method for URL objects such that the password attribute is not exposed.

    def test_to_repr_password(self):
        # Redact the password attribute from __repr__, but keep it on the object.
        urlobj = URL('https://user:password1@example.org/../something.txt')
        self.assertEqual(repr(urlobj), '<URL "https://user@example.org/something.txt">')
        self.assertEqual(urlobj.password, 'password1')
        self.assertEqual(
            str(urlobj), 'https://user:password1@example.org/something.txt'
        )

Closes #126.

@bbayles bbayles mentioned this pull request Feb 25, 2026
@bbayles bbayles merged commit 70a2ff0 into main Feb 25, 2026
9 checks passed
@bbayles bbayles deleted the repr-passwords-gh branch February 25, 2026 17:25
Comment on lines +274 to +277
password = self.password
self.password = ''
ret = f'<URL "{self.href}">'
self.password = password
Copy link

Choose a reason for hiding this comment

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

This looks very thread-unsafe to me. 😅 __repr__ usually isn't used in hot loops, so a copy should be fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll switch to copying in this PR:
#128

@bbayles bbayles mentioned this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Passwords in repr(url)

3 participants