Repository navigation
C#: Document custom redaction barriers - #23201
SkyCipherr wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 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
barrierModelexample targeting thefile-content-storebarrier kind. - Explains the
ReturnValueaccess 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)
|
QHelp previews: csharp/ql/src/Security Features/CWE-359/ExposureOfPrivateInformation.qhelpExposure of private informationPrivate 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. RecommendationEnsure 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 The ExampleThe 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
|
| <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> | ||
|
|
There was a problem hiding this comment.
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
qhelprelatively small.
Document how to model the return value of a custom C# redaction method for
cs/exposure-of-sensitive-information. The query help now includes abarrierModelexample using thefile-content-storekind.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.