Skip to content

C#: Document custom redaction barriers - #23201

Open
SkyCipherr wants to merge 1 commit into
github:mainfrom
SkyCipherr:codex/document-csharp-redaction-model
Open

SkyCipherr wants to merge 1 commit into
github:mainfrom
SkyCipherr:codex/document-csharp-redaction-model

Conversation

@SkyCipherr

Copy link
Copy Markdown
Contributor

Document how to model the return value of a custom C# redaction method for cs/exposure-of-sensitive-information. The query help now includes a barrierModel example using the file-content-store kind.

I rendered the query help as Markdown and loaded the YAML from the example into a model pack. On the same C# test database, the query reported both the raw write and the redacted write before loading the pack. With the pack loaded, only the raw write still alerted.

Fixes #23160.

@SkyCipherr
SkyCipherr requested a review from a team as a code owner November 23, 2026 05:35
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 05:35

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.

🟢 Approval recommended

The review evidence identifies no active issues, and the change is limited to documenting custom redaction barrier modeling and its relevant CodeQL guidance.

No open issues 🎉

What changed in this PR

Documents how C# users can model custom redaction methods as barriers for cs/exposure-of-sensitive-information, preventing alerts on redacted values while preserving alerts for raw sensitive data.

Changes:

  • Adds a YAML barrierModel example targeting the file-content-store barrier kind.
  • Explains the ReturnValue access path and links to the C# library-model customization documentation.
File Description
csharp/​ql/​src/​Security Features/​CWE-359/​ExposureOfPrivateInformation.qhelp Documents custom redaction barrier modeling and provides a relevant CodeQL documentation link.

Review effort: Lite (adaptive)

@github-actions

Copy link
Copy Markdown
Contributor

QHelp previews:

csharp/ql/src/Security Features/CWE-359/ExposureOfPrivateInformation.qhelp

Exposure of private information

Private information that is stored in an external location may be more vulnerable because that location may not be protected by the same access controls as other parts of the system.

Examples include log files, cookies and plain text storage on disk.

Recommendation

Ensure that private information is only stored in secure data locations.

If your application uses a custom method to redact private information, you can model its return value as a barrier for this query. For example, add the following data extension to a model pack for a CodeQLDocs.Redaction.Redact(string) method that removes the private information from its result.

extensions:
  - addsTo:
      pack: codeql/csharp-all
      extensible: barrierModel
    data:
      - ["CodeQLDocs", "Redaction", false, "Redact", "(System.String)", "", "ReturnValue", "file-content-store", "manual"]

The ReturnValue access path applies the barrier to the return value of the method. The file-content-store kind is used by this query when tracking flow to external locations.

Example

The following example shows some private data - an address - being passed to a HTTP handler. This private information is then stored in a log file. This log file on disk may be accessible to users that do not normally have access to this private data.

using System.Text;
using System.Web;
using System.Web.Security;

public class PrivateInformationHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext ctx)
    {
        string address = ctx.Request.QueryString["Address1"];
        logger.Info("User has address: " + address);
    }
}

References

Comment on lines +21 to +39
<p>
If your application uses a custom method to redact private information, you can model its return
value as a barrier for this query. For example, add the following data extension to a model pack
for a <code>CodeQLDocs.Redaction.Redact(string)</code> method that removes the private information
from its result.
</p>

<pre>extensions:
- addsTo:
pack: codeql/csharp-all
extensible: barrierModel
data:
- ["CodeQLDocs", "Redaction", false, "Redact", "(System.String)", "", "ReturnValue", "file-content-store", "manual"]</pre>

<p>
The <code>ReturnValue</code> access path applies the barrier to the return value of the method.
The <code>file-content-store</code> kind is used by this query when tracking flow to external locations.
</p>

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.

Thank you very much for the contribution. Yes, it is probably a good idea to mention that it is possible add sanitizers/barriers via models as data. However, we should probably just mention here that they can be added with the file-content-store kind and then refer to the public documentation on, how to write such models. This will

  • Make it easier to keep the documentation for MaD reasonably up-to-date (note that the public facing documentation now encourages the use of the JSON format for models) and keep it in a single location.
  • Keep the size of the qhelp relatively small.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants