Commit 67e6af4
Validate base64 in NegotiateAuthentication.GetOutgoingBlob(string) (#128691)
The `string`-based `NegotiateAuthentication.GetOutgoingBlob` overload
decoded the incoming blob with `Convert.FromBase64String`, which throws
`FormatException` on malformed input. Callers that hand off untrusted
client tokens (e.g. HTTP servers parsing `Authorization: Negotiate
<blob>`) had no way to get the documented `InvalidToken` status code for
that case without wrapping the call in a try/catch.
This change switches to `Convert.TryFromBase64String` and returns
`NegotiateAuthenticationStatusCode.InvalidToken` with a `null` outgoing
blob when decoding fails, matching the contract on the other failure
paths. The decode buffer is rented from `ArrayPool<byte>` and sliced to
the actual decoded length, then passed to the existing
`ReadOnlySpan<byte>` overload so we avoid both the throw and the extra
allocation on the happy path.
Tests cover a few representative malformed inputs (non-base64
characters, wrong length, misplaced padding).
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 6684fb2 commit 67e6af4
2 files changed
Lines changed: 43 additions & 10 deletions
File tree
- src/libraries/System.Net.Security
- src/System/Net/Security
- tests/UnitTests
Lines changed: 29 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
257 | | - | |
| 256 | + | |
| 257 | + | |
258 | 258 | | |
259 | | - | |
260 | | - | |
261 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
262 | 273 | | |
263 | | - | |
264 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
265 | 283 | | |
266 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
267 | 288 | | |
268 | | - | |
269 | | - | |
270 | 289 | | |
271 | 290 | | |
272 | 291 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
88 | 102 | | |
89 | 103 | | |
90 | 104 | | |
| |||
0 commit comments