Skip to content

C#: cs/exposure-of-sensitive-information has no documented way to mark a custom masking function as a sanitizer #23160

Backlog

Description

@keithmycek

Description

cs/exposure-of-sensitive-information (ExposureOfPrivateInformation) reports an email address written to a log even when it has been masked first by a project-specific function:

public static class EmailMasking
{
    // "alice@example.com" -> "a***e@example.com"
    public static string Mask(string? address) { /* keeps first and last letter before the '@' */ }
}

logger.LogInformation("To={To}", string.Join(", ", message.To.Select(EmailMasking.Mask)));

The alert is still raised on the log call. The taint step goes through the body of Mask (string indexing and concatenation), so a function whose purpose is to remove the sensitive part is not treated as removing it.

What I would like (enhancement)

  1. Document how to declare a masking or redaction function as a sanitizer for this query. From reading the source, ExposureOfPrivateInformationQuery.qll uses ExternalLocationSanitizer, which is barrierNode(this, "file-content-store"), so a Models-as-Data barrierModel with that kind should work. The kind name is not mentioned in the C# MaD documentation, so it is hard to discover.
  2. Optionally, recognise common masking and redaction helpers as barriers by default, the way some other queries treat encoders and validators.

Workaround I am trying

A model pack in .github/codeql/extensions (default setup):

extensions:
  - addsTo:
      pack: codeql/csharp-all
      extensible: barrierModel
    data:
      - ["My.Namespace", "EmailMasking", false, "Mask", "(System.String)", "", "ReturnValue", "file-content-store", "manual"]

If this is not the intended way to do it, a pointer to the right one would be appreciated.

Related alert type

Query: cs/exposure-of-sensitive-information. Language: C#. Code scanning default setup.

Activity

  1. jketema commented on Nov 17, 2026

    @jketema
    Contributor

    Hi @keithmycek,

    Our documentation seems very incomplete here. I'll raise this with the team.

    You're model pack approach seems the right one. See also https://docs.github.com/en/code-security/how-tos/find-and-fix-code-vulnerabilities/manage-your-configuration/edit-default-setup#extending-codeql-coverage-with-codeql-model-packs-in-default-setup, which I assume I'd already found.

  2. eshaanjain26 commented on Nov 29, 2026

    @eshaanjain26

    Thanks for confirming that the model pack approach is the right one. That confirmation helps, but I think the underlying problem is worth stating plainly: a user should not have to read query source code to find the barrier kind name for a query they are trying to configure.

    The string file-content-store is doing a lot of work here. It is not obvious that it covers log output, it is not mentioned in the C# Models as Data documentation, and a small typo in that string would fail quietly, leaving the alert in place with no hint that the model was never applied. Masking and redaction helpers are common in real codebases, so this is likely to affect more people than just this report.

    I would suggest three things. First, document the barrier kinds per query, ideally in the query help itself, so the kind for each query can be found from the alert page. Second, publish a worked example for a custom masking function, using this EmailMasking case, showing the full model pack and where it goes in default setup. Third, consider a warning when a barrierModel names a kind that no query in the pack uses, since that is a cheap way to catch spelling mistakes.

    On recognising common masking helpers by default, I would be cautious. A method called Mask that keeps the domain and parts of the local part may be fine for logs in one project and not acceptable in another, so the documented model route matters more than a built in guess.

    If useful, I can draft the documentation section and the worked example based on the model pack in this issue.

    Eshaan Jain, independent researcher (IEEE Senior Member)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions