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.

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