Fixing protected settings key leak - #2198
Merged
Mritunjay Tripathi (jaytripath) merged 1 commit intoJul 29, 2026
Merged
Conversation
Mritunjay Tripathi (jaytripath)
requested review from
a team,
Bhaskar Brahma (D1v38om83r) and
nkuchta
as code owners
July 23, 2026 20:36
Contributor
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
Mritunjay Tripathi (jaytripath)
requested a review
from Siddhartha Mathiharan (simathih)
July 23, 2026 21:51
Siddhartha Mathiharan (simathih)
approved these changes
Jul 27, 2026
Narine Mossikyan (NarineM)
approved these changes
Jul 29, 2026
Mritunjay Tripathi (jaytripath)
deleted the
mrtripathi/fixprotectedsettingsleak
branch
July 29, 2026 19:02
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.
Fixes a security incident where the decrypted protectedSettings value was leaked into extension logs.
Root cause:
On VMs where OpenSSL is misconfigured (missing /usr/local/ssl/openssl.cnf), openssl cms/smime prints a non-fatal warning to stderr. Because stderr was merged into the same stream as the decrypted stdout, the warning text got prepended to the decrypted JSON, breaking json.loads(). The resulting exception handler in HandlerUtil.py then logged the raw decrypted payload through redact_protected_settings() — but that helper only strips the outer, still-encrypted envelope fields (protectedSettings, protectedSettingsCertThumbprint); it doesn't recognize secrets inside the already-decrypted payload (e.g. workspaceKey), so the redaction was a silent no-op and the raw key was logged in plaintext.
Separately, agent.py's Install operation could crash outright (exit code 1) if logrotate.d doesn't exist on the VM, since the logrotate-config copy wasn't guarded against that failure.
Changes:
On JSON-decode failure of the decrypted protectedSettings, stop logging the (ineffectively "redacted") raw payload. Log only the exception message instead, which never contains the original content.
Changed the OpenSSL decrypt subprocess to capture stderr separately (subprocess.PIPE) instead of merging it into stdout (subprocess.STDOUT). Prevents non-fatal OpenSSL warnings from corrupting the JSON payload and causing decode failures in the first place — hardening the equivalent decrypt path used by Enable/metrics/syslog/transform-config operations.
Wrapped the logrotate config copyfile() in a try/except (mirroring the existing pattern for the sibling os.remove() call), so a missing logrotate.d directory logs a warning instead of failing the entire Install operation with exit code 1.
Work-item:
https://dev.azure.com/msazure/One/_workitems/edit/38590195