//****************************************************************************************************** // AntiForgeryConfig.cs - Gbtc // // Copyright © 2018, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 02/15/2018 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** #region [ Contributor License Agreements ] // Derived from AspNetWebStack (https://github.com/aspnet/AspNetWebStack) // Copyright (c) .NET Foundation. All rights reserved. // See NOTICE.txt file in Source folder for more information. #endregion using System.ComponentModel; namespace GSF.Web.Security { /// /// Provides programmatic configuration for the anti-forgery token system. /// public static class AntiForgeryConfig { internal const string AntiForgeryTokenFieldName = "__RequestVerificationToken"; private static string s_cookieName; /// /// Specifies an object that can provide additional data to put into all /// generated tokens and that can validate additional data in incoming /// tokens. /// public static IAntiForgeryAdditionalDataProvider AdditionalDataProvider { get; set; } /// /// Specifies the name of the cookie that is used by the anti-forgery /// system. /// /// /// If an explicit name is not provided, the system will automatically /// generate a name. /// public static string CookieName { get { return s_cookieName ?? (s_cookieName = AntiForgeryTokenFieldName); } set { s_cookieName = value; } } /// /// Specifies whether SSL is required for the anti-forgery system /// to operate. If this setting is 'true' and a non-SSL request /// comes into the system, all anti-forgery APIs will fail. /// public static bool RequireSsl { get; set; } /// /// Specifies whether to suppress the generation of X-Frame-Options header which /// is used to prevent ClickJacking. By default, the X-Frame-Options header is /// generated with the value SAMEORIGIN. If this setting is true, the /// X-Frame-Options header will not be generated for the response. /// public static bool SuppressXFrameOptionsHeader { get; set; } /// /// Specifies whether the anti-forgery system should skip checking /// for conditions that might indicate misuse of the system. Please /// use caution when setting this switch, as improper use could open /// security holes in the application. /// /// /// Setting this switch will disable several checks, including: /// - Identity.IsAuthenticated = true without Identity.Name being set /// [EditorBrowsable(EditorBrowsableState.Never)] public static bool SuppressIdentityHeuristicChecks { get; set; } } internal sealed class ReadOnlyAntiForgeryConfig { public IAntiForgeryAdditionalDataProvider AdditionalDataProvider => AntiForgeryConfig.AdditionalDataProvider; public string CookieName => AntiForgeryConfig.CookieName; public string FormFieldName => AntiForgeryConfig.AntiForgeryTokenFieldName; public bool RequireSSL => AntiForgeryConfig.RequireSsl; public bool SuppressIdentityHeuristicChecks => AntiForgeryConfig.SuppressIdentityHeuristicChecks; public bool SuppressXFrameOptionsHeader => AntiForgeryConfig.SuppressXFrameOptionsHeader; } }