Skip to content

[New Query - githubsecuritylab/cs/reverse-dns-user-controlled-bypass] - Sensitive action guarded by a reverse DNS host name - #279

Draft
felickz wants to merge 2 commits into
mainfrom
copilot/add-reverse-dns-query
Draft

felickz wants to merge 2 commits into
mainfrom
copilot/add-reverse-dns-query

Conversation

@felickz

@felickz felickz commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

The new C# query reports a condition on a reverse DNS host name that guards a sensitive action (CWE-350, CWE-807, CWE-247). An attacker who controls the PTR record of their own address controls that host name. The standard cs/user-controlled-bypass misses most of these cases for two reasons:

  • It treats only Dns.GetHostByAddress as a reverse lookup.
  • It propagates taint through == and Equals only when the other operand is a constant.
IPHostEntry hostInfo = Dns.GetHostEntry(peer);       // reverse lookup, not modelled by the standard query
if (hostInfo.HostName.Equals(trustedHostName))       // non-constant comparison, flow lost in the standard query
{
    AuthorizeUser(user);                              // reported here
}

Query (csharp/src/security/CWE-350/)

  • Sinks and sanitizers: reused from ConditionalBypassQuery, so a "sensitive action" means the same as in cs/user-controlled-bypass: login and authorization methods, and socket Send.
  • Sources:
    • every overload of Dns.GetHostByAddress
    • Dns.GetHostEntry and Dns.GetHostEntryAsync when parameter 0 is System.Net.IPAddress
  • Extra taint step: from either operand of a ComparisonTest to its result. It applies to this query only.
  • Metadata: @precision high, @security-severity 7.5, tagged experimental. With precision high, csharp.qls selects the query, so default-suite users get it from the release that ships it.
  • Query help: .qhelp with inline samples.

Test (csharp/test/security/CWE-350/ReverseDnsConditionalBypass/)

  • Reported (6): the vulnerable cases, the same 6 alerts as in the draft. They cover GetHostEntry, GetHostEntryAsync and GetHostByAddress; the Equals, == and EndsWith comparisons; and comparisons with a constant, a parameter and a local variable.
  • Not reported (safe):
    • the host name is only logged or printed
    • the decision uses IPAddress.Equals
    • a forward lookup of a constant name
    • the same Login call on both branches
  • Known false negative: a check that guards only Console.WriteLine.
  • Baseline: on the same test database, the standard cs/user-controlled-bypass reports only the GetHostByAddress case.

Changes from the draft

  • Id: cs/reverse-dns-user-controlled-bypass becomes githubsecuritylab/cs/reverse-dns-user-controlled-bypass. The .md help became .qhelp.
  • Postprocess: .qlref uses TestUtilities/PrettyPrintModels.ql with a .expected file instead of utils/test/InlineExpectationsTestQuery.ql. The upstream postprocess does not compile in this repository: the cached codeql/csharp-all pack has no lock file, so codeql/controlflow does not resolve.
  • Fixture markers: the draft's $ Alert markers are now BAD/GOOD comments. I checked them once, before the conversion, with a temporary inline postprocess (not committed), and they all matched.
  • Expected file: MaD:1892 becomes MaD:1, with a models section from the postprocess.
  • options: unchanged. The framework assembly references resolve, so the shared stubs are not needed.

Known limitations

  • GetHostEntry(string) called with an address literal is not modelled, and neither is BeginGetHostEntry/EndGetHostEntry.
  • GetHostByAddress flows are also reported by cs/user-controlled-bypass.
  • The comparison step is general: comparing the host name with any value counts as a decision based on it.
  • Performance has been measured only on the test database (about 1.4 s, with one global taint configuration). It needs measuring on real code.

Follow-ups for the maintainer

  • Bump the githubsecuritylab/codeql-csharp-queries version at release time.
  • Add a real-project true positive.
  • Optional: add a shared inline-expectations postprocess under csharp/test/TestUtilities/ so C# tests can use $ Alert markers.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 06:30

Copilot AI left a comment

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.

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

…lp and test

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 06:45
@felickz felickz changed the title [WIP] Add C# query for security decision based on reverse DNS lookup [New Query - githubsecuritylab/cs/reverse-dns-user-controlled-bypass] - Sensitive action guarded by a reverse DNS host name Nov 26, 2026
public void GetHostByAddressBad(IPAddress peer, string user, string password)
{
#pragma warning disable CS0618
IPHostEntry hostInfo = Dns.GetHostByAddress(peer); // source

Copilot AI left a comment

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.

🟡 Changes recommended

The fixtures lack parameter-based Equals cases with the reverse-DNS host name on either side, leaving the motivating scenario and propagation from both operands unverified.

1 open issue

Review effort: Balanced

predicate isAdditionalFlowStep(DataFlow::Node pred, DataFlow::Node succ) {
exists(ComparisonTest ct |
ct.getExpr() = succ.asExpr() and
ct.getAnArgument() = pred.asExpr()
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.

C#: add a query for a security decision based on a reverse DNS lookup

3 participants