microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.8

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/src/Microsoft.Teams.Core/HttpRequestExtensions.cs

33lines · modeblame

beaf8909Corina1 months ago1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.AspNetCore.Http;
5
6namespace Microsoft.Teams.Core;
7
8/// <summary>
9/// Extension methods for <see cref="HttpRequest"/>.
10/// </summary>
11public 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>
17public static string? GetCorrelationVector(this HttpRequest request)
18{
19if (request == null)
20{
21return string.Empty;
22}
23
24string? correlationVector = request.Headers["MS-CV"].FirstOrDefault();
25
26if (string.IsNullOrEmpty(correlationVector))
27{
28return string.Empty;
29}
30
31return correlationVector.Replace(Environment.NewLine, "", StringComparison.Ordinal);
32}
33}