Skip to content

SG-44103 Mask secrets in git descriptors URLs - #1131

Open
carlos-villavicencio-adsk wants to merge 3 commits into
masterfrom
ticket/SG-44103-redact-git-credentials
Open

SG-44103 Mask secrets in git descriptors URLs#1131
carlos-villavicencio-adsk wants to merge 3 commits into
masterfrom
ticket/SG-44103-redact-git-credentials

Conversation

@carlos-villavicencio-adsk

Copy link
Copy Markdown
Contributor

This pull request introduces significant improvements to the handling of sensitive information in Git-related descriptors by ensuring that credentials (such as usernames, passwords, or tokens) are sanitized from logs, error messages, and string representations. The changes add utility functions for sanitizing URLs and exceptions, and update several methods and exception handlers to use these utilities, thereby reducing the risk of leaking secrets in logs or error outputs.

These changes collectively improve the security and robustness of the codebase by systematically preventing accidental exposure of sensitive credentials in logs and error messages.

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.38028% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.08%. Comparing base (889c1cd) to head (97e3e2f).

Files with missing lines Patch % Lines
python/tank/descriptor/io_descriptor/git.py 72.54% 14 Missing ⚠️
python/tank/descriptor/io_descriptor/git_branch.py 25.00% 9 Missing ⚠️
python/tank/descriptor/io_descriptor/git_tag.py 62.50% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (63.38%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1131      +/-   ##
==========================================
- Coverage   80.09%   80.08%   -0.02%     
==========================================
  Files         203      203              
  Lines       19537    19596      +59     
==========================================
+ Hits        15649    15694      +45     
- Misses       3888     3902      +14     
Flag Coverage Δ
Linux 79.53% <61.97%> (-0.01%) ⬇️
Python-3.10 79.90% <63.38%> (-0.02%) ⬇️
Python-3.11 79.80% <63.38%> (-0.02%) ⬇️
Python-3.13 79.80% <63.38%> (-0.02%) ⬇️
Python-3.9 79.86% <63.38%> (-0.02%) ⬇️
Windows 79.57% <61.97%> (+<0.01%) ⬆️
macOS 79.50% <61.97%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@carlos-villavicencio-adsk
carlos-villavicencio-adsk requested a review from a team August 28, 2026 14:56
elif isinstance(cmd, str):
# For string commands, we need to be more careful
# Split on spaces but preserve quoted strings
import shlex

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not importing this at the top of the file?

return subprocess_check_output(*args, **kwargs)


def _sanitize_url(url):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add Python typing info for all new methods, please?

Comment on lines +126 to +134
if isinstance(exc, SubprocessCalledProcessError):
sanitized_cmd = _sanitize_command(exc.cmd)
# Create a new exception with the sanitized command
new_exc = SubprocessCalledProcessError(
exc.returncode, sanitized_cmd, output=exc.output
)
# Preserve the original traceback
return new_exc
return exc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fail first?

Suggested change
if isinstance(exc, SubprocessCalledProcessError):
sanitized_cmd = _sanitize_command(exc.cmd)
# Create a new exception with the sanitized command
new_exc = SubprocessCalledProcessError(
exc.returncode, sanitized_cmd, output=exc.output
)
# Preserve the original traceback
return new_exc
return exc
if isinstance(exc, SubprocessCalledProcessError):
return exc
sanitized_cmd = _sanitize_command(exc.cmd)
# Create a new exception with the sanitized command
new_exc = SubprocessCalledProcessError(
exc.returncode, sanitized_cmd, output=exc.output
)
# Preserve the original traceback
return new_exc

)
except Exception as e:
# Sanitize any credentials that might be in the exception or path
from ...util.process import SubprocessCalledProcessError

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why importing here and not top of the file?

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.

2 participants