Set secret request URIs on HttpRequestMessage
The secret URI API belongs to HttpRequestMessage, not HttpClient. HttpRequestMessage.SetSecretRequestUri(SecretText) keeps a credential-bearing URI protected, and the prepared request is sent with HttpClient.Send.
- microsoftlayer
- securitydomain
- 2examples
- 3pull requests
Rule on GitHub · microsoft layer · security · BC 23.. · tier official · derived
Description
The secret URI API belongs to HttpRequestMessage, not HttpClient. HttpRequestMessage.SetSecretRequestUri(SecretText) keeps a credential-bearing URI protected, and the prepared request is sent with HttpClient.Send. Companion APIs also accept SecretText, including HttpHeaders.Add for authorization headers and HttpContent.WriteFrom for secret request bodies.
Best Practice
Compose a secret URI with SecretStrSubstNo, call Request.SetSecretRequestUri(SecretUri), set the request method, and send the request with HttpClient.Send(Request, Response). For authorization, get the request headers, add a SecretText value, and use ContainsSecret when checking for that header. See sample: secrettext-with-httpclient.good.al.
Anti Pattern
Holding a credential in Text, interpolating it with StrSubstNo or concatenation, and passing that plain text to HttpClient.Get or HttpHeaders.Add. The secret-aware request and header APIs remove the need to materialize the value as Text. This HTTP-sink rule supersedes the generic secrettext-for-credentials.md rule at the same location. See sample: secrettext-with-httpclient.bad.al.
Examples
Names
- SecretText.SecretStrSubstNo(Text [, SecretText,…]) Method (names SecretStrSubstNo)
- HttpHeaders.ContainsSecret(Text) Method (names ContainsSecret)
- Text.StrSubstNo(Text [, Any,…]) Method (names StrSubstNo)
Changed by
- #174 Make BCQuality documentation easier for partners to get started, 2026-09-09
- #108 Complete AL review knowledge readiness, 2026-07-15
- #92 Correct security and privacy knowledge guidance, 2026-07-14
From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).