From 4a5f2d16bbeab0e16f3786d5058872c013c686f9 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 11 Mar 2019 14:18:17 -0700 Subject: [PATCH] Make pubinternal types in Antiforgery internal (#8340) * Make pubinternal types in Antiforgery internal Adresses https://github.com/aspnet/AspNetCore/issues/8308 --- src/Antiforgery/build.cmd | 3 + src/Antiforgery/build.sh | 7 + ...ft.AspNetCore.Antiforgery.netcoreapp3.0.cs | 143 ------------------ .../AntiforgeryServiceCollectionExtensions.cs | 1 - .../src/Internal/AntiforgeryFeature.cs | 6 +- .../Internal/AntiforgeryLoggerExtensions.cs | 2 +- .../src/Internal/AntiforgeryOptionsSetup.cs | 20 ++- .../AntiforgerySerializationContext.cs | 8 +- ...ySerializationContextPooledObjectPolicy.cs | 7 +- .../src/Internal/AntiforgeryToken.cs | 6 +- src/Antiforgery/src/Internal/BinaryBlob.cs | 6 +- .../src/Internal/CryptographyAlgorithms.cs | 4 +- .../src/Internal/DefaultAntiforgery.cs | 7 +- ...efaultAntiforgeryAdditionalDataProvider.cs | 10 +- .../DefaultAntiforgeryTokenGenerator.cs | 6 +- .../DefaultAntiforgeryTokenSerializer.cs | 6 +- .../Internal/DefaultAntiforgeryTokenStore.cs | 4 +- .../src/Internal/DefaultClaimUidExtractor.cs | 6 +- .../src/Internal/IAntiforgeryFeature.cs | 6 +- .../Internal/IAntiforgeryTokenGenerator.cs | 6 +- .../Internal/IAntiforgeryTokenSerializer.cs | 6 +- .../src/Internal/IAntiforgeryTokenStore.cs | 6 +- .../src/Internal/IClaimUidExtractor.cs | 7 +- .../Microsoft.AspNetCore.Antiforgery.csproj | 3 +- src/Antiforgery/startvs.cmd | 3 + .../AntiforgeryOptionsSetupTest.cs | 0 .../{Internal => }/AntiforgeryTokenTest.cs | 0 .../test/{Internal => }/BinaryBlobTest.cs | 0 .../{Internal => }/DefaultAntiforgeryTest.cs | 0 .../DefaultAntiforgeryTokenGeneratorTest.cs | 0 .../DefaultAntiforgeryTokenSerializerTest.cs | 0 .../DefaultAntiforgeryTokenStoreTest.cs | 0 .../DefaultClaimUidExtractorTest.cs | 0 33 files changed, 81 insertions(+), 208 deletions(-) create mode 100644 src/Antiforgery/build.cmd create mode 100644 src/Antiforgery/build.sh create mode 100644 src/Antiforgery/startvs.cmd rename src/Antiforgery/test/{Internal => }/AntiforgeryOptionsSetupTest.cs (100%) rename src/Antiforgery/test/{Internal => }/AntiforgeryTokenTest.cs (100%) rename src/Antiforgery/test/{Internal => }/BinaryBlobTest.cs (100%) rename src/Antiforgery/test/{Internal => }/DefaultAntiforgeryTest.cs (100%) rename src/Antiforgery/test/{Internal => }/DefaultAntiforgeryTokenGeneratorTest.cs (100%) rename src/Antiforgery/test/{Internal => }/DefaultAntiforgeryTokenSerializerTest.cs (100%) rename src/Antiforgery/test/{Internal => }/DefaultAntiforgeryTokenStoreTest.cs (100%) rename src/Antiforgery/test/{Internal => }/DefaultClaimUidExtractorTest.cs (100%) diff --git a/src/Antiforgery/build.cmd b/src/Antiforgery/build.cmd new file mode 100644 index 0000000000..033fe6f614 --- /dev/null +++ b/src/Antiforgery/build.cmd @@ -0,0 +1,3 @@ +@ECHO OFF +SET RepoRoot=%~dp0..\.. +%RepoRoot%\build.cmd -projects %~dp0\**\*.*proj %* diff --git a/src/Antiforgery/build.sh b/src/Antiforgery/build.sh new file mode 100644 index 0000000000..7046bb98a0 --- /dev/null +++ b/src/Antiforgery/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euo pipefail + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +repo_root="$DIR/../.." +"$repo_root/build.sh" --projects "$DIR/**/*.*proj" "$@" diff --git a/src/Antiforgery/ref/Microsoft.AspNetCore.Antiforgery.netcoreapp3.0.cs b/src/Antiforgery/ref/Microsoft.AspNetCore.Antiforgery.netcoreapp3.0.cs index 51f908b19b..5eb2c8be65 100644 --- a/src/Antiforgery/ref/Microsoft.AspNetCore.Antiforgery.netcoreapp3.0.cs +++ b/src/Antiforgery/ref/Microsoft.AspNetCore.Antiforgery.netcoreapp3.0.cs @@ -39,149 +39,6 @@ namespace Microsoft.AspNetCore.Antiforgery bool ValidateAdditionalData(Microsoft.AspNetCore.Http.HttpContext context, string additionalData); } } -namespace Microsoft.AspNetCore.Antiforgery.Internal -{ - public partial class AntiforgeryFeature : Microsoft.AspNetCore.Antiforgery.Internal.IAntiforgeryFeature - { - public AntiforgeryFeature() { } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken CookieToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool HaveDeserializedCookieToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool HaveDeserializedRequestToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool HaveGeneratedNewCookieToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool HaveStoredNewCookieToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken NewCookieToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string NewCookieTokenString { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken NewRequestToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string NewRequestTokenString { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken RequestToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - } - public partial class AntiforgeryOptionsSetup : Microsoft.Extensions.Options.ConfigureOptions - { - public AntiforgeryOptionsSetup(Microsoft.Extensions.Options.IOptions dataProtectionOptionsAccessor) : base (default(System.Action)) { } - public static void ConfigureOptions(Microsoft.AspNetCore.Antiforgery.AntiforgeryOptions options, Microsoft.AspNetCore.DataProtection.DataProtectionOptions dataProtectionOptions) { } - } - public partial class AntiforgerySerializationContext - { - public AntiforgerySerializationContext() { } - public System.IO.BinaryReader Reader { get { throw null; } } - public System.Security.Cryptography.SHA256 Sha256 { get { throw null; } } - public System.IO.MemoryStream Stream { get { throw null; } } - public System.IO.BinaryWriter Writer { get { throw null; } } - public char[] GetChars(int count) { throw null; } - public void Reset() { } - } - public partial class AntiforgerySerializationContextPooledObjectPolicy : Microsoft.Extensions.ObjectPool.IPooledObjectPolicy - { - public AntiforgerySerializationContextPooledObjectPolicy() { } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgerySerializationContext Create() { throw null; } - public bool Return(Microsoft.AspNetCore.Antiforgery.Internal.AntiforgerySerializationContext obj) { throw null; } - } - public sealed partial class AntiforgeryToken - { - public AntiforgeryToken() { } - public string AdditionalData { get { throw null; } set { } } - public Microsoft.AspNetCore.Antiforgery.Internal.BinaryBlob ClaimUid { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool IsCookieToken { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.AspNetCore.Antiforgery.Internal.BinaryBlob SecurityToken { get { throw null; } set { } } - public string Username { get { throw null; } set { } } - } - [System.Diagnostics.DebuggerDisplayAttribute("{DebuggerString}")] - public sealed partial class BinaryBlob : System.IEquatable - { - public BinaryBlob(int bitLength) { } - public BinaryBlob(int bitLength, byte[] data) { } - public int BitLength { get { throw null; } } - public bool Equals(Microsoft.AspNetCore.Antiforgery.Internal.BinaryBlob other) { throw null; } - public override bool Equals(object obj) { throw null; } - public byte[] GetData() { throw null; } - public override int GetHashCode() { throw null; } - } - public static partial class CryptographyAlgorithms - { - public static System.Security.Cryptography.SHA256 CreateSHA256() { throw null; } - } - public partial class DefaultAntiforgery : Microsoft.AspNetCore.Antiforgery.IAntiforgery - { - public DefaultAntiforgery(Microsoft.Extensions.Options.IOptions antiforgeryOptionsAccessor, Microsoft.AspNetCore.Antiforgery.Internal.IAntiforgeryTokenGenerator tokenGenerator, Microsoft.AspNetCore.Antiforgery.Internal.IAntiforgeryTokenSerializer tokenSerializer, Microsoft.AspNetCore.Antiforgery.Internal.IAntiforgeryTokenStore tokenStore, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { } - public Microsoft.AspNetCore.Antiforgery.AntiforgeryTokenSet GetAndStoreTokens(Microsoft.AspNetCore.Http.HttpContext httpContext) { throw null; } - public Microsoft.AspNetCore.Antiforgery.AntiforgeryTokenSet GetTokens(Microsoft.AspNetCore.Http.HttpContext httpContext) { throw null; } - [System.Diagnostics.DebuggerStepThroughAttribute] - public System.Threading.Tasks.Task IsRequestValidAsync(Microsoft.AspNetCore.Http.HttpContext httpContext) { throw null; } - public void SetCookieTokenAndHeader(Microsoft.AspNetCore.Http.HttpContext httpContext) { } - protected virtual void SetDoNotCacheHeaders(Microsoft.AspNetCore.Http.HttpContext httpContext) { } - [System.Diagnostics.DebuggerStepThroughAttribute] - public System.Threading.Tasks.Task ValidateRequestAsync(Microsoft.AspNetCore.Http.HttpContext httpContext) { throw null; } - } - public partial class DefaultAntiforgeryAdditionalDataProvider : Microsoft.AspNetCore.Antiforgery.IAntiforgeryAdditionalDataProvider - { - public DefaultAntiforgeryAdditionalDataProvider() { } - public virtual string GetAdditionalData(Microsoft.AspNetCore.Http.HttpContext context) { throw null; } - public virtual bool ValidateAdditionalData(Microsoft.AspNetCore.Http.HttpContext context, string additionalData) { throw null; } - } - public partial class DefaultAntiforgeryTokenGenerator : Microsoft.AspNetCore.Antiforgery.Internal.IAntiforgeryTokenGenerator - { - public DefaultAntiforgeryTokenGenerator(Microsoft.AspNetCore.Antiforgery.Internal.IClaimUidExtractor claimUidExtractor, Microsoft.AspNetCore.Antiforgery.IAntiforgeryAdditionalDataProvider additionalDataProvider) { } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken GenerateCookieToken() { throw null; } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken GenerateRequestToken(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken cookieToken) { throw null; } - public bool IsCookieTokenValid(Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken cookieToken) { throw null; } - public bool TryValidateTokenSet(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken cookieToken, Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken requestToken, out string message) { throw null; } - } - public partial class DefaultAntiforgeryTokenSerializer : Microsoft.AspNetCore.Antiforgery.Internal.IAntiforgeryTokenSerializer - { - public DefaultAntiforgeryTokenSerializer(Microsoft.AspNetCore.DataProtection.IDataProtectionProvider provider, Microsoft.Extensions.ObjectPool.ObjectPool pool) { } - public Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken Deserialize(string serializedToken) { throw null; } - public string Serialize(Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken token) { throw null; } - } - public partial class DefaultAntiforgeryTokenStore : Microsoft.AspNetCore.Antiforgery.Internal.IAntiforgeryTokenStore - { - public DefaultAntiforgeryTokenStore(Microsoft.Extensions.Options.IOptions optionsAccessor) { } - public string GetCookieToken(Microsoft.AspNetCore.Http.HttpContext httpContext) { throw null; } - [System.Diagnostics.DebuggerStepThroughAttribute] - public System.Threading.Tasks.Task GetRequestTokensAsync(Microsoft.AspNetCore.Http.HttpContext httpContext) { throw null; } - public void SaveCookieToken(Microsoft.AspNetCore.Http.HttpContext httpContext, string token) { } - } - public partial class DefaultClaimUidExtractor : Microsoft.AspNetCore.Antiforgery.Internal.IClaimUidExtractor - { - public DefaultClaimUidExtractor(Microsoft.Extensions.ObjectPool.ObjectPool pool) { } - public string ExtractClaimUid(System.Security.Claims.ClaimsPrincipal claimsPrincipal) { throw null; } - public static System.Collections.Generic.IList GetUniqueIdentifierParameters(System.Collections.Generic.IEnumerable claimsIdentities) { throw null; } - } - public partial interface IAntiforgeryFeature - { - Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken CookieToken { get; set; } - bool HaveDeserializedCookieToken { get; set; } - bool HaveDeserializedRequestToken { get; set; } - bool HaveGeneratedNewCookieToken { get; set; } - bool HaveStoredNewCookieToken { get; set; } - Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken NewCookieToken { get; set; } - string NewCookieTokenString { get; set; } - Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken NewRequestToken { get; set; } - string NewRequestTokenString { get; set; } - Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken RequestToken { get; set; } - } - public partial interface IAntiforgeryTokenGenerator - { - Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken GenerateCookieToken(); - Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken GenerateRequestToken(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken cookieToken); - bool IsCookieTokenValid(Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken cookieToken); - bool TryValidateTokenSet(Microsoft.AspNetCore.Http.HttpContext httpContext, Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken cookieToken, Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken requestToken, out string message); - } - public partial interface IAntiforgeryTokenSerializer - { - Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken Deserialize(string serializedToken); - string Serialize(Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryToken token); - } - public partial interface IAntiforgeryTokenStore - { - string GetCookieToken(Microsoft.AspNetCore.Http.HttpContext httpContext); - System.Threading.Tasks.Task GetRequestTokensAsync(Microsoft.AspNetCore.Http.HttpContext httpContext); - void SaveCookieToken(Microsoft.AspNetCore.Http.HttpContext httpContext, string token); - } - public partial interface IClaimUidExtractor - { - string ExtractClaimUid(System.Security.Claims.ClaimsPrincipal claimsPrincipal); - } -} namespace Microsoft.Extensions.DependencyInjection { public static partial class AntiforgeryServiceCollectionExtensions diff --git a/src/Antiforgery/src/AntiforgeryServiceCollectionExtensions.cs b/src/Antiforgery/src/AntiforgeryServiceCollectionExtensions.cs index 8cc76d6f94..969c17f632 100644 --- a/src/Antiforgery/src/AntiforgeryServiceCollectionExtensions.cs +++ b/src/Antiforgery/src/AntiforgeryServiceCollectionExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Antiforgery; -using Microsoft.AspNetCore.Antiforgery.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.ObjectPool; using Microsoft.Extensions.Options; diff --git a/src/Antiforgery/src/Internal/AntiforgeryFeature.cs b/src/Antiforgery/src/Internal/AntiforgeryFeature.cs index ad2a38501d..632c835df8 100644 --- a/src/Antiforgery/src/Internal/AntiforgeryFeature.cs +++ b/src/Antiforgery/src/Internal/AntiforgeryFeature.cs @@ -1,12 +1,12 @@ // 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. -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { /// /// Used to hold per-request state. /// - public class AntiforgeryFeature : IAntiforgeryFeature + internal class AntiforgeryFeature : IAntiforgeryFeature { public bool HaveDeserializedCookieToken { get; set; } @@ -31,4 +31,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal // Always false if NewCookieToken is null. Never store null cookie token or re-store cookie token from request. public bool HaveStoredNewCookieToken { get; set; } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/AntiforgeryLoggerExtensions.cs b/src/Antiforgery/src/Internal/AntiforgeryLoggerExtensions.cs index 1f55fecf96..6bc7e60cd5 100644 --- a/src/Antiforgery/src/Internal/AntiforgeryLoggerExtensions.cs +++ b/src/Antiforgery/src/Internal/AntiforgeryLoggerExtensions.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { internal static class AntiforgeryLoggerExtensions { diff --git a/src/Antiforgery/src/Internal/AntiforgeryOptionsSetup.cs b/src/Antiforgery/src/Internal/AntiforgeryOptionsSetup.cs index a6bc826351..0227068130 100644 --- a/src/Antiforgery/src/Internal/AntiforgeryOptionsSetup.cs +++ b/src/Antiforgery/src/Internal/AntiforgeryOptionsSetup.cs @@ -1,26 +1,34 @@ // 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; using System.Linq; using System.Text; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public class AntiforgeryOptionsSetup : ConfigureOptions + internal class AntiforgeryOptionsSetup : IConfigureOptions { - public AntiforgeryOptionsSetup(IOptions dataProtectionOptionsAccessor) - : base((options) => ConfigureOptions(options, dataProtectionOptionsAccessor.Value)) + private readonly DataProtectionOptions _dataProtectionOptions; + + public AntiforgeryOptionsSetup(IOptions dataProtectionOptions) { + _dataProtectionOptions = dataProtectionOptions.Value; } - public static void ConfigureOptions(AntiforgeryOptions options, DataProtectionOptions dataProtectionOptions) + public void Configure(AntiforgeryOptions options) { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + if (options.Cookie.Name == null) { - var applicationId = dataProtectionOptions.ApplicationDiscriminator ?? string.Empty; + var applicationId = _dataProtectionOptions.ApplicationDiscriminator ?? string.Empty; options.Cookie.Name = AntiforgeryOptions.DefaultCookiePrefix + ComputeCookieName(applicationId); } } diff --git a/src/Antiforgery/src/Internal/AntiforgerySerializationContext.cs b/src/Antiforgery/src/Internal/AntiforgerySerializationContext.cs index 6d697fa0da..87fe89d49c 100644 --- a/src/Antiforgery/src/Internal/AntiforgerySerializationContext.cs +++ b/src/Antiforgery/src/Internal/AntiforgerySerializationContext.cs @@ -1,13 +1,13 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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.IO; using System.Security.Cryptography; using System.Text; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public class AntiforgerySerializationContext + internal class AntiforgerySerializationContext { // Avoid allocating 256 bytes (the default) and using 18 (the AntiforgeryToken minimum). 64 bytes is enough for // a short username or claim UID and some additional data. MemoryStream bumps capacity to 256 if exceeded. @@ -138,4 +138,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal } } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/AntiforgerySerializationContextPooledObjectPolicy.cs b/src/Antiforgery/src/Internal/AntiforgerySerializationContextPooledObjectPolicy.cs index 0a6163141b..c88bd8fbfa 100644 --- a/src/Antiforgery/src/Internal/AntiforgerySerializationContextPooledObjectPolicy.cs +++ b/src/Antiforgery/src/Internal/AntiforgerySerializationContextPooledObjectPolicy.cs @@ -1,12 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// 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 Microsoft.Extensions.ObjectPool; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public class AntiforgerySerializationContextPooledObjectPolicy - : IPooledObjectPolicy + internal class AntiforgerySerializationContextPooledObjectPolicy : IPooledObjectPolicy { public AntiforgerySerializationContext Create() { diff --git a/src/Antiforgery/src/Internal/AntiforgeryToken.cs b/src/Antiforgery/src/Internal/AntiforgeryToken.cs index 78294f730c..59e9b83e5a 100644 --- a/src/Antiforgery/src/Internal/AntiforgeryToken.cs +++ b/src/Antiforgery/src/Internal/AntiforgeryToken.cs @@ -1,9 +1,9 @@ // 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. -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public sealed class AntiforgeryToken + internal sealed class AntiforgeryToken { internal const int SecurityTokenBitLength = 128; internal const int ClaimUidBitLength = 256; @@ -50,4 +50,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal } } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/BinaryBlob.cs b/src/Antiforgery/src/Internal/BinaryBlob.cs index 88c34571c0..0e5039295a 100644 --- a/src/Antiforgery/src/Internal/BinaryBlob.cs +++ b/src/Antiforgery/src/Internal/BinaryBlob.cs @@ -8,12 +8,12 @@ using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { // Represents a binary blob (token) that contains random data. // Useful for binary data inside a serialized stream. [DebuggerDisplay("{DebuggerString}")] - public sealed class BinaryBlob : IEquatable + internal sealed class BinaryBlob : IEquatable { private static readonly RandomNumberGenerator _randomNumberGenerator = RandomNumberGenerator.Create(); private readonly byte[] _data; @@ -114,4 +114,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal return areEqual; } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/CryptographyAlgorithms.cs b/src/Antiforgery/src/Internal/CryptographyAlgorithms.cs index 644b4e6234..936b93f0c6 100644 --- a/src/Antiforgery/src/Internal/CryptographyAlgorithms.cs +++ b/src/Antiforgery/src/Internal/CryptographyAlgorithms.cs @@ -3,9 +3,9 @@ using System.Security.Cryptography; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public static class CryptographyAlgorithms + internal static class CryptographyAlgorithms { public static SHA256 CreateSHA256() { diff --git a/src/Antiforgery/src/Internal/DefaultAntiforgery.cs b/src/Antiforgery/src/Internal/DefaultAntiforgery.cs index cef46be893..8259fd540d 100644 --- a/src/Antiforgery/src/Internal/DefaultAntiforgery.cs +++ b/src/Antiforgery/src/Internal/DefaultAntiforgery.cs @@ -9,13 +9,13 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { /// /// Provides access to the antiforgery system, which provides protection against /// Cross-site Request Forgery (XSRF, also called CSRF) attacks. /// - public class DefaultAntiforgery : IAntiforgery + internal class DefaultAntiforgery : IAntiforgery { private readonly AntiforgeryOptions _options; private readonly IAntiforgeryTokenGenerator _tokenGenerator; @@ -133,12 +133,11 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal } // Validate - string message; var result = _tokenGenerator.TryValidateTokenSet( httpContext, deserializedCookieToken, deserializedRequestToken, - out message); + out string message); if (result) { diff --git a/src/Antiforgery/src/Internal/DefaultAntiforgeryAdditionalDataProvider.cs b/src/Antiforgery/src/Internal/DefaultAntiforgeryAdditionalDataProvider.cs index ad28453495..3aa9b13e27 100644 --- a/src/Antiforgery/src/Internal/DefaultAntiforgeryAdditionalDataProvider.cs +++ b/src/Antiforgery/src/Internal/DefaultAntiforgeryAdditionalDataProvider.cs @@ -3,24 +3,24 @@ using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { /// /// A default implementation. /// - public class DefaultAntiforgeryAdditionalDataProvider : IAntiforgeryAdditionalDataProvider + internal class DefaultAntiforgeryAdditionalDataProvider : IAntiforgeryAdditionalDataProvider { /// - public virtual string GetAdditionalData(HttpContext context) + public string GetAdditionalData(HttpContext context) { return string.Empty; } /// - public virtual bool ValidateAdditionalData(HttpContext context, string additionalData) + public bool ValidateAdditionalData(HttpContext context, string additionalData) { // Default implementation does not understand anything but empty data. return string.IsNullOrEmpty(additionalData); } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenGenerator.cs b/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenGenerator.cs index 872f7ed18c..03994ec1e9 100644 --- a/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenGenerator.cs +++ b/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenGenerator.cs @@ -7,9 +7,9 @@ using System.Security.Claims; using System.Security.Principal; using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public class DefaultAntiforgeryTokenGenerator : IAntiforgeryTokenGenerator + internal class DefaultAntiforgeryTokenGenerator : IAntiforgeryTokenGenerator { private readonly IClaimUidExtractor _claimUidExtractor; private readonly IAntiforgeryAdditionalDataProvider _additionalDataProvider; @@ -235,4 +235,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal return null; } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenSerializer.cs b/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenSerializer.cs index d71f2a2185..73a0e0ad63 100644 --- a/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenSerializer.cs +++ b/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenSerializer.cs @@ -7,9 +7,9 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.ObjectPool; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public class DefaultAntiforgeryTokenSerializer : IAntiforgeryTokenSerializer + internal class DefaultAntiforgeryTokenSerializer : IAntiforgeryTokenSerializer { private static readonly string Purpose = "Microsoft.AspNetCore.Antiforgery.AntiforgeryToken.v1"; private const byte TokenVersion = 0x01; @@ -185,4 +185,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal } } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenStore.cs b/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenStore.cs index b0fdd5cd93..63f3be4236 100644 --- a/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenStore.cs +++ b/src/Antiforgery/src/Internal/DefaultAntiforgeryTokenStore.cs @@ -8,9 +8,9 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public class DefaultAntiforgeryTokenStore : IAntiforgeryTokenStore + internal class DefaultAntiforgeryTokenStore : IAntiforgeryTokenStore { private readonly AntiforgeryOptions _options; diff --git a/src/Antiforgery/src/Internal/DefaultClaimUidExtractor.cs b/src/Antiforgery/src/Internal/DefaultClaimUidExtractor.cs index 1a7ef394a0..fb4d386516 100644 --- a/src/Antiforgery/src/Internal/DefaultClaimUidExtractor.cs +++ b/src/Antiforgery/src/Internal/DefaultClaimUidExtractor.cs @@ -7,12 +7,12 @@ using System.Diagnostics; using System.Security.Claims; using Microsoft.Extensions.ObjectPool; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { /// /// Default implementation of . /// - public class DefaultClaimUidExtractor : IClaimUidExtractor + internal class DefaultClaimUidExtractor : IClaimUidExtractor { private readonly ObjectPool _pool; @@ -146,4 +146,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal } } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/IAntiforgeryFeature.cs b/src/Antiforgery/src/Internal/IAntiforgeryFeature.cs index 2404359de7..c96db16708 100644 --- a/src/Antiforgery/src/Internal/IAntiforgeryFeature.cs +++ b/src/Antiforgery/src/Internal/IAntiforgeryFeature.cs @@ -1,6 +1,6 @@ -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public interface IAntiforgeryFeature + internal interface IAntiforgeryFeature { AntiforgeryToken CookieToken { get; set; } @@ -22,4 +22,4 @@ AntiforgeryToken RequestToken { get; set; } } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/IAntiforgeryTokenGenerator.cs b/src/Antiforgery/src/Internal/IAntiforgeryTokenGenerator.cs index c0dff86047..59cb3118cd 100644 --- a/src/Antiforgery/src/Internal/IAntiforgeryTokenGenerator.cs +++ b/src/Antiforgery/src/Internal/IAntiforgeryTokenGenerator.cs @@ -3,12 +3,12 @@ using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { /// /// Generates and validates antiforgery tokens. /// - public interface IAntiforgeryTokenGenerator + internal interface IAntiforgeryTokenGenerator { /// /// Generates a new random cookie token. @@ -47,4 +47,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal AntiforgeryToken requestToken, out string message); } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/IAntiforgeryTokenSerializer.cs b/src/Antiforgery/src/Internal/IAntiforgeryTokenSerializer.cs index 134516e8c9..be160879e0 100644 --- a/src/Antiforgery/src/Internal/IAntiforgeryTokenSerializer.cs +++ b/src/Antiforgery/src/Internal/IAntiforgeryTokenSerializer.cs @@ -1,12 +1,12 @@ // 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. -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { // Abstracts out the serialization process for an antiforgery token - public interface IAntiforgeryTokenSerializer + internal interface IAntiforgeryTokenSerializer { AntiforgeryToken Deserialize(string serializedToken); string Serialize(AntiforgeryToken token); } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/IAntiforgeryTokenStore.cs b/src/Antiforgery/src/Internal/IAntiforgeryTokenStore.cs index 1b4aa8ec05..dd3f29e835 100644 --- a/src/Antiforgery/src/Internal/IAntiforgeryTokenStore.cs +++ b/src/Antiforgery/src/Internal/IAntiforgeryTokenStore.cs @@ -4,9 +4,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { - public interface IAntiforgeryTokenStore + internal interface IAntiforgeryTokenStore { string GetCookieToken(HttpContext httpContext); @@ -19,4 +19,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal void SaveCookieToken(HttpContext httpContext, string token); } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Internal/IClaimUidExtractor.cs b/src/Antiforgery/src/Internal/IClaimUidExtractor.cs index 72ab230fb4..29d264789d 100644 --- a/src/Antiforgery/src/Internal/IClaimUidExtractor.cs +++ b/src/Antiforgery/src/Internal/IClaimUidExtractor.cs @@ -1,15 +1,14 @@ // 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.Collections.Generic; using System.Security.Claims; -namespace Microsoft.AspNetCore.Antiforgery.Internal +namespace Microsoft.AspNetCore.Antiforgery { /// /// This interface can extract unique identifers for a . /// - public interface IClaimUidExtractor + internal interface IClaimUidExtractor { /// /// Extracts claims identifier. @@ -18,4 +17,4 @@ namespace Microsoft.AspNetCore.Antiforgery.Internal /// The claims identifier. string ExtractClaimUid(ClaimsPrincipal claimsPrincipal); } -} \ No newline at end of file +} diff --git a/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj b/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj index c34c52157b..d416ab8383 100644 --- a/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj +++ b/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj @@ -1,10 +1,9 @@ - + An antiforgery system for ASP.NET Core designed to generate and validate tokens to prevent Cross-Site Request Forgery attacks. netcoreapp3.0 true - $(NoWarn);CS1591 true aspnetcore;antiforgery diff --git a/src/Antiforgery/startvs.cmd b/src/Antiforgery/startvs.cmd new file mode 100644 index 0000000000..65f2092506 --- /dev/null +++ b/src/Antiforgery/startvs.cmd @@ -0,0 +1,3 @@ +@ECHO OFF + +%~dp0..\..\startvs.cmd %~dp0Antiforgery.sln diff --git a/src/Antiforgery/test/Internal/AntiforgeryOptionsSetupTest.cs b/src/Antiforgery/test/AntiforgeryOptionsSetupTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/AntiforgeryOptionsSetupTest.cs rename to src/Antiforgery/test/AntiforgeryOptionsSetupTest.cs diff --git a/src/Antiforgery/test/Internal/AntiforgeryTokenTest.cs b/src/Antiforgery/test/AntiforgeryTokenTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/AntiforgeryTokenTest.cs rename to src/Antiforgery/test/AntiforgeryTokenTest.cs diff --git a/src/Antiforgery/test/Internal/BinaryBlobTest.cs b/src/Antiforgery/test/BinaryBlobTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/BinaryBlobTest.cs rename to src/Antiforgery/test/BinaryBlobTest.cs diff --git a/src/Antiforgery/test/Internal/DefaultAntiforgeryTest.cs b/src/Antiforgery/test/DefaultAntiforgeryTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/DefaultAntiforgeryTest.cs rename to src/Antiforgery/test/DefaultAntiforgeryTest.cs diff --git a/src/Antiforgery/test/Internal/DefaultAntiforgeryTokenGeneratorTest.cs b/src/Antiforgery/test/DefaultAntiforgeryTokenGeneratorTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/DefaultAntiforgeryTokenGeneratorTest.cs rename to src/Antiforgery/test/DefaultAntiforgeryTokenGeneratorTest.cs diff --git a/src/Antiforgery/test/Internal/DefaultAntiforgeryTokenSerializerTest.cs b/src/Antiforgery/test/DefaultAntiforgeryTokenSerializerTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/DefaultAntiforgeryTokenSerializerTest.cs rename to src/Antiforgery/test/DefaultAntiforgeryTokenSerializerTest.cs diff --git a/src/Antiforgery/test/Internal/DefaultAntiforgeryTokenStoreTest.cs b/src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/DefaultAntiforgeryTokenStoreTest.cs rename to src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs diff --git a/src/Antiforgery/test/Internal/DefaultClaimUidExtractorTest.cs b/src/Antiforgery/test/DefaultClaimUidExtractorTest.cs similarity index 100% rename from src/Antiforgery/test/Internal/DefaultClaimUidExtractorTest.cs rename to src/Antiforgery/test/DefaultClaimUidExtractorTest.cs