Skip to content

[CodeQL] Suppress Random Dictionary Key Warning in SqlDependencyUtils#4276

Open
benrr101 wants to merge 1 commit into
mainfrom
dev/russellben/codeql-random
Open

[CodeQL] Suppress Random Dictionary Key Warning in SqlDependencyUtils#4276
benrr101 wants to merge 1 commit into
mainfrom
dev/russellben/codeql-random

Conversation

@benrr101
Copy link
Copy Markdown
Contributor

Description

This PR addresses a CodeQL issue that was raised recently. The issue is that we are using "randomly generated" dictionary keys. Technically this is true, as the keys we're using in this case is partially generated by a Guid.NewGuid() call. The "fix" for this is to replace the Guid.NewGuid() calls with cryptographically secure random number generation. However, there's little reason to go to this trouble - even with hundreds of thousands of IDs being generated, the risk of a collision is exceedingly small. Therefore, rather than rewrite the key generation (and likely all the other instances where IDs are generated by GUIDs), I've opted to suppress this specific line of code.

Issues

CodeQL issue.

🤖

Suppression message generated by 🤖

@benrr101 benrr101 added this to the 7.1.0-preview2 milestone May 12, 2026
@benrr101 benrr101 requested a review from a team as a code owner May 12, 2026 19:12
Copilot AI review requested due to automatic review settings May 12, 2026 19:12
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board May 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to address a CodeQL alert in SqlDependencyUtils by suppressing a warning related to “randomly generated” identifiers used during query notification correlation, rather than changing the identifier generation logic.

Changes:

  • Normalized whitespace in a couple of comments.
  • Added a CodeQL suppression justification comment near the notificationId mapping logic in AddCommandEntry.

Comment on lines +219 to 220
_commandHashToNotificationId.Add(commandHash, notificationId); // CodeQL [SM04207] This value is an opaque query-notification correlation identifier, not a secret or security token. It is used only for uniqueness and exact dictionary lookup after SQL Server round-trips the user data. Guid.NewGuid provides sufficient collision resistance for the expected in-process notification cardinality, and changing the generator would not materially improve security.
_notificationIdToDependenciesHash.Add(notificationId, dependencyList);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Don't ask me. This is the line CodeQL is complaining about 🤷‍♂️

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.

@benrr101 What you've added on line 219 looks correct to me.


// map command hash to notification we just created to reuse it for the next client
_commandHashToNotificationId.Add(commandHash, notificationId);
_commandHashToNotificationId.Add(commandHash, notificationId); // CodeQL [SM04207] This value is an opaque query-notification correlation identifier, not a secret or security token. It is used only for uniqueness and exact dictionary lookup after SQL Server round-trips the user data. Guid.NewGuid provides sufficient collision resistance for the expected in-process notification cardinality, and changing the generator would not materially improve security.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The suppression comment formats accepted by CodeQL are all ugly. It's silly that we can't use multi-line comments to avoid these hugely long lines.

I worked around it it here:

// SqlClient is a library and provides support to acquire access

You can try that format if you want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree it is ugly. But I really don't want to kick off a full rebuild and re-review just to tweak the formatting a tiny bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

5 participants