Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReleasePrep][2023.04.05]RI of dev into main #9455

Merged
merged 6 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/NuGetGallery.Core/Infrastructure/TableErrorLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public override string Log(Error error)
return pos.ToString(CultureInfo.InvariantCulture);
}

private void Obfuscate(Error error)
public static void Obfuscate(Error error)
{
error.User = string.Empty;
if (error.Form != null)
Expand Down Expand Up @@ -218,10 +218,19 @@ private void Obfuscate(Error error)

error.ServerVariables["HTTP_X_NUGET_APIKEY"] = string.Empty;

var forwardedIps = error.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(',');
var obfuscatedIps = forwardedIps.Select(Obfuscator.ObfuscateIp);

error.ServerVariables["HTTP_X_FORWARDED_FOR"] = string.Join(",", obfuscatedIps);
var forwardedIps = error.ServerVariables["HTTP_X_FORWARDED_FOR"]?
.Split(',')
.Select(x => x.Trim())
.Where(x => x.Length > 0)
.ToList();
if (forwardedIps != null)
{
var obfuscatedIps = string.Join(",", forwardedIps.Select(Obfuscator.ObfuscateIp));
if (!string.IsNullOrWhiteSpace(obfuscatedIps))
{
error.ServerVariables["HTTP_X_FORWARDED_FOR"] = obfuscatedIps;
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/NuGetGallery/App_Code/ViewHelpers.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ var hlp = new AccordionHelper(name, formModelStatePrefix, expanded, page);
</div>
if (!disabled)
{
<div class="panel panel-default panel-collapse collapse @(expanded ? "in" : string.Empty)"
aria-expanded="@(expanded ? "true" : "false")" id="@id-container">
<div aria-controls="panel-body" class="panel panel-default panel-collapse collapse @(expanded ? "in" : string.Empty)"
id="@id-container">
<div class="panel-body">
@content(MvcHtmlString.Empty)
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/NuGetGallery/Views/Users/ApiKeys.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@

<div class="row">
<div class="col-sm-12 form-group">
<b id="select-scopes" class="ms-fontSize-xl">Select Scopes</b>
<br />
<h4 id="select-scopes" class="ms-fontSize-xl"><b>Select Scopes</b></h4>
<span class="has-error">
<span class="help-block" data-bind="text: ScopesError" aria-live="polite" role="alert"></span>
</span>
Expand Down Expand Up @@ -394,7 +393,7 @@
<!-- /ko -->
<div class="row">
<div class="col-sm-12">
<b class="ms-fontSize-xl">Select Packages</b>
<h4 class="ms-fontSize-xl"><b>Select Packages</b></h4>
<p>
To select which packages to associate with a key, use a glob pattern, select
individual packages, or both.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Linq;
using Elmah;
using Xunit;

namespace NuGetGallery.Infrastructure
{
public class TableErrorLogFacts
{
public class TheObfuscateMethod
{
[Fact]
public void HandlesMissingForwardedHeader()
{
// Arrange
var error = new Error();

// Act
TableErrorLog.Obfuscate(error);

// Assert
Assert.DoesNotContain("HTTP_X_FORWARDED_FOR", error.ServerVariables.Keys.Cast<string>());
}

[Theory]
[InlineData("", "")]
[InlineData(",", ",")]
[InlineData(" ", " ")]
[InlineData("127.0.0.1", "127.0.0.0")]
[InlineData("127.1.2.3,127.1.2.4", "127.1.2.0,127.1.2.0")]
[InlineData("127.1.2.3 , 127.1.2.4", "127.1.2.0,127.1.2.0")]
public void ObfuscatesForwardedHeader(string input, string expected)
{
// Arrange
var error = new Error();
error.ServerVariables["HTTP_X_FORWARDED_FOR"] = input;

// Act
TableErrorLog.Obfuscate(error);

// Assert
Assert.Equal(expected, error.ServerVariables["HTTP_X_FORWARDED_FOR"]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="Infrastructure\Mail\Messages\SymbolPackageValidationFailedMessageFacts.cs" />
<Compile Include="Infrastructure\Mail\Messages\SymbolPackageValidationTakingTooLongMessageFacts.cs" />
<Compile Include="Infrastructure\Mail\TestMessageServiceConfiguration.cs" />
<Compile Include="Infrastructure\TableErrorLogFacts.cs" />
<Compile Include="Packaging\ManifestValidatorFacts.cs" />
<Compile Include="Packaging\PackageIdValidatorTest.cs" />
<Compile Include="Packaging\PackageMetadataFacts.cs" />
Expand Down