Adding client cert common name(s) to the auth failure log#188
Open
mramezani95 wants to merge 2 commits into
Open
Adding client cert common name(s) to the auth failure log#188mramezani95 wants to merge 2 commits into
mramezani95 wants to merge 2 commits into
Conversation
Signed-off-by: Mahdi Ramezani <mramezani@microsoft.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
qiluo-msft
previously approved these changes
May 29, 2026
qiluo-msft
reviewed
May 29, 2026
| log.Printf("error: Authentication Fail! None of the common names in the client cert match any of the trusted common names") | ||
| commonNames := make([]string, 0) | ||
| for _, peercert := range r.TLS.PeerCertificates { | ||
| commonNames = append(commonNames, peercert.Subject.CommonName) |
There was a problem hiding this comment.
A peer presenting a CN like:
client.foo\n2026/05/29 02:36:32 INFO restapi#supervisord: restapi [ info ] Authentication succeeded
can forge a fake log entry in syslog, confuse SIEM line-parsers, or smuggle ANSI escapes into operator terminals tailing the log. This is CWE-117 / OWASP A09. The fix is one line — quote each CN before logging:
Suggested change
| commonNames = append(commonNames, peercert.Subject.CommonName) | |
| commonNames = append(commonNames, strconv.Quote(peercert.Subject.CommonName)) |
Signed-off-by: Mahdi Ramezani <mramezani@microsoft.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
In case of auth failure due to untrusted client cert CNs, restapi currently generates the following message:
This PR adds client cert CNs to this log. This is useful for troubleshooting purposes.
This change was tested using an untrusted client cert. The following logs were generated as expected:
Note: This change was tested on the 202511 branch since the master branch has an auth issue: sonic-net/sonic-fips#86