-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gh-oblt/replace-token-with-app
- Loading branch information
Showing
15 changed files
with
526 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
on: | ||
workflow_run: | ||
workflows: | ||
- test-windows | ||
types: | ||
- completed | ||
|
||
permissions: | ||
contents: read | ||
actions: read | ||
checks: write | ||
|
||
jobs: | ||
report: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: elastic/oblt-actions/test-report@v1 | ||
with: | ||
artifact: /test-results(.*)/ | ||
name: 'Test Repot $1' | ||
path: "**/*.xml" | ||
reporter: java-junit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Elastic.Apm.Api; | ||
using Elastic.Apm.Config; | ||
using Elastic.Apm.Helpers; | ||
using Elastic.Apm.Model; | ||
#if NET6_0_OR_GREATER | ||
using System.Buffers; | ||
#endif | ||
|
||
namespace Elastic.Apm.Filters | ||
{ | ||
/// <summary> | ||
/// Redacts items from the cookie list of the Cookie request header. | ||
/// </summary> | ||
internal class CookieHeaderRedactionFilter | ||
{ | ||
private const string CookieHeader = "Cookie"; | ||
|
||
public static IError Filter(IError error) | ||
{ | ||
if (error is Error e && e.Context is not null) | ||
HandleCookieHeader(e.Context?.Request?.Headers, e.Configuration.SanitizeFieldNames); | ||
return error; | ||
} | ||
|
||
public static ITransaction Filter(ITransaction transaction) | ||
{ | ||
if (transaction is Transaction { IsContextCreated: true }) | ||
HandleCookieHeader(transaction.Context?.Request?.Headers, transaction.Configuration.SanitizeFieldNames); | ||
return transaction; | ||
} | ||
|
||
// internal for testing | ||
internal static void HandleCookieHeader(Dictionary<string, string> headers, IReadOnlyList<WildcardMatcher> sanitizeFieldNames) | ||
{ | ||
if (headers is not null) | ||
{ | ||
// Realistically, this should be more than enough for all sensible scenarios | ||
// e.g. Cookies | cookies | COOKIES | ||
const int maxKeys = 4; | ||
|
||
#if NET6_0_OR_GREATER | ||
var matchedKeys = ArrayPool<string>.Shared.Rent(maxKeys); | ||
var matchedValues = ArrayPool<string>.Shared.Rent(maxKeys); | ||
#else | ||
var matchedKeys = new string[maxKeys]; | ||
var matchedValues = new string[maxKeys]; | ||
#endif | ||
var matchedCount = 0; | ||
|
||
foreach (var header in headers) | ||
{ | ||
if (matchedCount == maxKeys) | ||
break; | ||
|
||
if (header.Key.Equals(CookieHeader, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
matchedKeys[matchedCount] = header.Key; | ||
matchedValues[matchedCount] = CookieHeaderRedacter.Redact(header.Value, sanitizeFieldNames); | ||
matchedCount++; | ||
} | ||
} | ||
|
||
var replacedCount = 0; | ||
|
||
foreach (var headerKey in matchedKeys) | ||
{ | ||
if (replacedCount == matchedCount) | ||
break; | ||
|
||
if (headerKey is not null) | ||
{ | ||
headers[headerKey] = matchedValues[replacedCount]; | ||
replacedCount++; | ||
} | ||
} | ||
|
||
#if NET6_0_OR_GREATER | ||
ArrayPool<string>.Shared.Return(matchedKeys); | ||
ArrayPool<string>.Shared.Return(matchedValues); | ||
#endif | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.