microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Teams.Core/HttpRequestExtensions.cs
33lines · modeblame
beaf8909Corina1 months ago | 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. | |
| 3 | | |
| 4 | using Microsoft.AspNetCore.Http; | |
| 5 | | |
| 6 | namespace Microsoft.Teams.Core; | |
| 7 | | |
| 8 | /// <summary> | |
| 9 | /// Extension methods for <see cref="HttpRequest"/>. | |
| 10 | /// </summary> | |
| 11 | public static class HttpRequestExtensions | |
| 12 | { | |
| 13 | /// <summary> | |
| 14 | /// Gets the Microsoft Correlation Vector (MS-CV) from the request headers, if present. | |
| 15 | /// The value is sanitized to prevent log forging attacks by removing newline characters. | |
| 16 | /// </summary> | |
| 17 | public static string? GetCorrelationVector(this HttpRequest request) | |
| 18 | { | |
| 19 | if (request == null) | |
| 20 | { | |
| 21 | return string.Empty; | |
| 22 | } | |
| 23 | | |
| 24 | string? correlationVector = request.Headers["MS-CV"].FirstOrDefault(); | |
| 25 | | |
| 26 | if (string.IsNullOrEmpty(correlationVector)) | |
| 27 | { | |
| 28 | return string.Empty; | |
| 29 | } | |
| 30 | | |
| 31 | return correlationVector.Replace(Environment.NewLine, "", StringComparison.Ordinal); | |
| 32 | } | |
| 33 | } |