diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorComponentsWeb-CSharp/Pages/_Host.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorComponentsWeb-CSharp/Pages/_Host.cshtml index 66a7aa0628..4eff49f3b4 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorComponentsWeb-CSharp/Pages/_Host.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorComponentsWeb-CSharp/Pages/_Host.cshtml @@ -9,16 +9,7 @@ RazorComponentsWeb-CSharp - - - - - - + diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_CookieConsentPartial.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_CookieConsentPartial.cshtml deleted file mode 100644 index 999a0ed5bf..0000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_CookieConsentPartial.cshtml +++ /dev/null @@ -1,25 +0,0 @@ -@using Microsoft.AspNetCore.Http.Features - -@{ - var consentFeature = Context.Features.Get(); - var showBanner = !consentFeature?.CanTrack ?? false; - var cookieString = consentFeature?.CreateConsentCookie(); -} - -@if (showBanner) -{ - - -} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml index 5506d943d3..198a48ef80 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_Layout.cshtml @@ -4,17 +4,7 @@ @ViewData["Title"] - Company.WebApplication1 - - - - - - - + @@ -44,37 +34,17 @@ -
- -
+
@RenderBody() -
-
- + - - - - - - - - + + @RenderSection("Scripts", required: false) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_ValidationScriptsPartial.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_ValidationScriptsPartial.cshtml index c442042cb0..2ef6ebd63d 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_ValidationScriptsPartial.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -1,18 +1,5 @@ - - - - - - - - + + + + + diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs index ea58c1f885..b3737d13d8 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Startup.cs @@ -52,11 +52,6 @@ namespace Company.WebApplication1 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.Configure(options => - { - // This lambda determines whether user consent for non-essential cookies is needed for a given request. - options.CheckConsentNeeded = context => true; - }); #if (IndividualLocalAuth) services.AddDbContext(options => @@ -152,8 +147,6 @@ namespace Company.WebApplication1 #endif app.UseStaticFiles(); - app.UseCookiePolicy(); - app.UseRouting(); #if (OrganizationalAuth || IndividualAuth) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs index 0638b76cab..698ab40241 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Startup.cs @@ -52,11 +52,6 @@ namespace Company.WebApplication1 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.Configure(options => - { - // This lambda determines whether user consent for non-essential cookies is needed for a given request. - options.CheckConsentNeeded = context => true; - }); #if (IndividualLocalAuth) services.AddDbContext(options => @@ -153,8 +148,6 @@ namespace Company.WebApplication1 #endif app.UseStaticFiles(); - app.UseCookiePolicy(); - app.UseRouting(); #if (OrganizationalAuth || IndividualAuth) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_CookieConsentPartial.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_CookieConsentPartial.cshtml deleted file mode 100644 index 8f96286262..0000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_CookieConsentPartial.cshtml +++ /dev/null @@ -1,25 +0,0 @@ -@using Microsoft.AspNetCore.Http.Features - -@{ - var consentFeature = Context.Features.Get(); - var showBanner = !consentFeature?.CanTrack ?? false; - var cookieString = consentFeature?.CreateConsentCookie(); -} - -@if (showBanner) -{ - - -} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml index b370df12dd..5ae18ac630 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_Layout.cshtml @@ -4,17 +4,7 @@ @ViewData["Title"] - Company.WebApplication1 - - - - - - - + @@ -44,39 +34,17 @@ -
- -
+
@RenderBody() -
-
- +
© copyrightYear - Company.WebApplication1 - Privacy
- - - - - - - - - + + - @RenderSection("Scripts", required: false) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_ValidationScriptsPartial.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_ValidationScriptsPartial.cshtml index 3c0e077702..e8933599b8 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_ValidationScriptsPartial.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-CSharp/Views/Shared/_ValidationScriptsPartial.cshtml @@ -1,18 +1,2 @@ - - - - - - - - + + \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_CookieConsentPartial.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_CookieConsentPartial.cshtml deleted file mode 100644 index 999a0ed5bf..0000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_CookieConsentPartial.cshtml +++ /dev/null @@ -1,25 +0,0 @@ -@using Microsoft.AspNetCore.Http.Features - -@{ - var consentFeature = Context.Features.Get(); - var showBanner = !consentFeature?.CanTrack ?? false; - var cookieString = consentFeature?.CreateConsentCookie(); -} - -@if (showBanner) -{ - - -} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml index be03f90c3d..6f62720a1f 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_Layout.cshtml @@ -5,16 +5,7 @@ @ViewData["Title"] - Company.WebApplication1 - - - - - - + @@ -39,37 +30,18 @@ -
- -
+
@RenderBody() -
-
- +
© copyrightYear - Company.WebApplication1 - Privacy
- - - - - - - - + + + @RenderSection("Scripts", required: false) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_ValidationScriptsPartial.cshtml b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_ValidationScriptsPartial.cshtml index c442042cb0..bc03630978 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_ValidationScriptsPartial.cshtml +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/StarterWeb-FSharp/Views/Shared/_ValidationScriptsPartial.cshtml @@ -1,18 +1,3 @@ - - - - - - - - + + + diff --git a/src/ProjectTemplates/test/CdnScriptTagTests.cs b/src/ProjectTemplates/test/CdnScriptTagTests.cs deleted file mode 100644 index 3261e1f917..0000000000 --- a/src/ProjectTemplates/test/CdnScriptTagTests.cs +++ /dev/null @@ -1,293 +0,0 @@ -// 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 AngleSharp; -using AngleSharp.Dom; -using AngleSharp.Dom.Html; -using AngleSharp.Parser.Html; -using Microsoft.AspNetCore.Server.IntegrationTesting; -using Microsoft.Extensions.Logging.Abstractions; -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net.Http; -using System.Reflection; -using System.Security.Cryptography; -using System.Threading.Tasks; -using Templates.Test.Helpers; -using Xunit; -using Xunit.Abstractions; - -namespace Templates.Test -{ - public class CdnScriptTagTests : IDisposable - { - private readonly ITestOutputHelper _output; - private readonly HttpClient _httpClient; - private static List _scriptTags; - private static List _linkTags; - private static readonly string[] _packages; - - static CdnScriptTagTests() - { - var searchPattern = "*.nupkg"; - _packages = Directory.EnumerateFiles( - ResolveFolder("ArtifactsShippingPackagesDir"), - searchPattern) - .Concat(Directory.EnumerateFiles( - ResolveFolder("ArtifactsNonShippingPackagesDir"), - searchPattern)) - .ToArray(); - - _scriptTags = new List(); - _linkTags = new List(); - foreach (var packagePath in _packages) - { - var tags = GetTags(packagePath); - _scriptTags.AddRange(tags.scripts); - _linkTags.AddRange(tags.links); - } - } - - private static string ResolveFolder(string folder) => - typeof(CdnScriptTagTests).Assembly - .GetCustomAttributes() - .Single(a => a.Key == folder).Value; - - public CdnScriptTagTests(ITestOutputHelper output) - { - _output = output; - _httpClient = new HttpClient(); - } - - public static IEnumerable SubresourceIntegrityCheckScriptData - { - get - { - var scriptTags = _scriptTags - .Where(st => st.FallbackSrc != null) - .Select(st => new object[] { st }); - Assert.NotEmpty(scriptTags); - return scriptTags; - } - } - - public static IEnumerable SubresourceIntegrityCheckLinkData - { - get - { - var linkTags = _linkTags - .Where(st => st.FallbackHRef != null) - .Select(st => new object[] { st }); - Assert.NotEmpty(linkTags); - return linkTags; - } - } - - [Theory] - [MemberData(nameof(SubresourceIntegrityCheckScriptData))] - public async Task CheckScriptSubresourceIntegrity(ScriptTag scriptTag) - { - var expectedIntegrity = await GetShaIntegrity(scriptTag); - if (!string.Equals(expectedIntegrity, scriptTag.Integrity, StringComparison.OrdinalIgnoreCase)) - { - Assert.False(true, $"Expected {scriptTag.Src} to have Integrity '{expectedIntegrity}' but it had '{scriptTag.Integrity}'."); - } - } - - [Theory] - [MemberData(nameof(SubresourceIntegrityCheckLinkData))] - public async Task CheckLinkSubresourceIntegrity(LinkTag linkTag) - { - string expectedIntegrity = await GetShaIntegrity(linkTag); - if (!expectedIntegrity.Equals(linkTag.Integrity, StringComparison.OrdinalIgnoreCase)) - { - Assert.False(true, $"Expected {linkTag.HRef} to have Integrity '{expectedIntegrity}' but it had '{linkTag.Integrity}'."); - } - } - - public static IEnumerable FallbackSrcCheckData - { - get - { - var scriptTags = _scriptTags - .Where(st => st.FallbackSrc != null) - .Select(st => new object[] { st }); - Assert.NotEmpty(scriptTags); - return scriptTags; - } - } - - [Theory] - [MemberData(nameof(FallbackSrcCheckData))] - public async Task FallbackSrcContent_Matches_CDNContent(ScriptTag scriptTag) - { - var fallbackSrc = scriptTag.FallbackSrc - .TrimStart('~') - .TrimStart('/'); - - var cdnContent = await GetStringFromCDN(scriptTag.Src); - var fallbackSrcContent = GetFileContentFromArchive(scriptTag, fallbackSrc); - - Assert.Equal(RemoveLineEndings(cdnContent), RemoveLineEndings(fallbackSrcContent)); - } - - public struct LinkTag - { - public string Rel; - public string HRef; - public string FallbackHRef; - public string Integrity; - - public override string ToString() - { - return $"{HRef}, {Integrity}"; - } - } - - public struct ScriptTag - { - public string Src; - public string Integrity; - public string FallbackSrc; - public string FileName; - public string Entry; - - public override string ToString() - { - return $"{Src}, {Entry}"; - } - } - - private async Task GetStringFromCDN(string src) - { - var response = await GetFromCDN(src); - return await response.Content.ReadAsStringAsync(); - } - - private async Task GetByteArrayFromCDN(string src) - { - var response = await GetFromCDN(src); - return await response.Content.ReadAsByteArrayAsync(); - } - - private async Task GetFromCDN(string src) - { - var logger = NullLogger.Instance; - return await RetryHelper.RetryRequest(async () => - { - var request = new HttpRequestMessage(HttpMethod.Get, new Uri(src)); - return await _httpClient.SendAsync(request); - }, logger); - } - - private Task GetShaIntegrity(ScriptTag scriptTag) - { - return GetShaIntegrity(scriptTag.Integrity, scriptTag.Src); - } - - private Task GetShaIntegrity(LinkTag linkTag) - { - return GetShaIntegrity(linkTag.Integrity, linkTag.HRef); - } - - private async Task GetShaIntegrity(string integrity, string src) - { - var prefix = integrity.Substring(0, 6); - var respStream = await GetByteArrayFromCDN(src); - using (HashAlgorithm alg = string.Equals(prefix, "sha256") ? (HashAlgorithm)SHA256.Create() : (HashAlgorithm)SHA384.Create()) - { - var hash = alg.ComputeHash(respStream); - return $"{prefix}-" + Convert.ToBase64String(hash); - } - } - - private static string GetFileContentFromArchive(ScriptTag scriptTag, string relativeFilePath) - { - var file = _packages.Single(f => f.EndsWith(scriptTag.FileName)); - using (var zip = new ZipArchive(File.OpenRead(file), ZipArchiveMode.Read, leaveOpen: false)) - { - var entry = zip.Entries - .Where(e => e.FullName.EndsWith(relativeFilePath, StringComparison.OrdinalIgnoreCase)) - .FirstOrDefault(); - - if (entry != null) - { - using (var reader = new StreamReader(entry.Open())) - { - return reader.ReadToEnd(); - } - } - } - return null; - } - - private static (List scripts, List links) GetTags(string zipFile) - { - var scriptTags = new List(); - var linkTags = new List(); - using (var zip = new ZipArchive(File.OpenRead(zipFile), ZipArchiveMode.Read, leaveOpen: false)) - { - foreach (var entry in zip.Entries) - { - if (!string.Equals(".cshtml", Path.GetExtension(entry.Name), StringComparison.OrdinalIgnoreCase)) - { - continue; - } - - IHtmlDocument htmlDocument; - var options = new HtmlParserOptions - { - IsStrictMode = false, - IsEmbedded = false, - }; - var config = Configuration.Default; - var htmlParser = new HtmlParser(options, config); - using (var reader = new StreamReader(entry.Open())) - { - htmlDocument = htmlParser.Parse(entry.Open()); - } - - foreach (IElement link in htmlDocument.Body.GetElementsByTagName("link")) - { - linkTags.Add(new LinkTag - { - HRef = link.GetAttribute("href"), - Integrity = link.GetAttribute("integrity"), - FallbackHRef = link.GetAttribute("asp-fallback-href"), - }); - } - - foreach (var scriptElement in htmlDocument.Scripts) - { - var fallbackSrcAttribute = scriptElement.Attributes - .FirstOrDefault(attr => string.Equals("asp-fallback-src", attr.Name, StringComparison.OrdinalIgnoreCase)); - - scriptTags.Add(new ScriptTag - { - Src = scriptElement.Source, - Integrity = scriptElement.Integrity, - FallbackSrc = fallbackSrcAttribute?.Value, - FileName = Path.GetFileName(zipFile), - Entry = entry.FullName - }); - } - - } - } - return (scriptTags, linkTags); - } - - private static string RemoveLineEndings(string originalString) - { - return originalString.Replace("\r\n", "").Replace("\n", ""); - } - - public void Dispose() - { - _httpClient.Dispose(); - } - } -} diff --git a/src/ProjectTemplates/test/template-baselines.json b/src/ProjectTemplates/test/template-baselines.json index a6e919620c..565cbecd16 100644 --- a/src/ProjectTemplates/test/template-baselines.json +++ b/src/ProjectTemplates/test/template-baselines.json @@ -22,7 +22,6 @@ "Pages/Privacy.cshtml.cs", "Pages/_ViewImports.cshtml", "Pages/_ViewStart.cshtml", - "Pages/Shared/_CookieConsentPartial.cshtml", "Pages/Shared/_Layout.cshtml", "Pages/Shared/_LoginPartial.cshtml", "Pages/Shared/_ValidationScriptsPartial.cshtml", @@ -82,7 +81,6 @@ "Pages/Privacy.cshtml.cs", "Pages/_ViewImports.cshtml", "Pages/_ViewStart.cshtml", - "Pages/Shared/_CookieConsentPartial.cshtml", "Pages/Shared/_Layout.cshtml", "Pages/Shared/_ValidationScriptsPartial.cshtml", "Properties/launchSettings.json", @@ -141,7 +139,6 @@ "Pages/Privacy.cshtml.cs", "Pages/_ViewImports.cshtml", "Pages/_ViewStart.cshtml", - "Pages/Shared/_CookieConsentPartial.cshtml", "Pages/Shared/_Layout.cshtml", "Pages/Shared/_LoginPartial.cshtml", "Pages/Shared/_ValidationScriptsPartial.cshtml", @@ -201,7 +198,6 @@ "Pages/Privacy.cshtml.cs", "Pages/_ViewImports.cshtml", "Pages/_ViewStart.cshtml", - "Pages/Shared/_CookieConsentPartial.cshtml", "Pages/Shared/_Layout.cshtml", "Pages/Shared/_LoginPartial.cshtml", "Pages/Shared/_ValidationScriptsPartial.cshtml", @@ -261,7 +257,6 @@ "Pages/Privacy.cshtml.cs", "Pages/_ViewImports.cshtml", "Pages/_ViewStart.cshtml", - "Pages/Shared/_CookieConsentPartial.cshtml", "Pages/Shared/_Layout.cshtml", "Pages/Shared/_ValidationScriptsPartial.cshtml", "Properties/launchSettings.json", @@ -320,7 +315,6 @@ "Pages/Privacy.cshtml.cs", "Pages/_ViewImports.cshtml", "Pages/_ViewStart.cshtml", - "Pages/Shared/_CookieConsentPartial.cshtml", "Pages/Shared/_Layout.cshtml", "Pages/Shared/_LoginPartial.cshtml", "Pages/Shared/_ValidationScriptsPartial.cshtml", @@ -484,7 +478,6 @@ "Views/Home/Index.cshtml", "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", - "Views/Shared/_CookieConsentPartial.cshtml", "Views/Shared/_Layout.cshtml", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", @@ -543,7 +536,6 @@ "Views/Home/Index.cshtml", "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", - "Views/Shared/_CookieConsentPartial.cshtml", "Views/Shared/_Layout.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", @@ -601,7 +593,6 @@ "Views/Home/Index.cshtml", "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", - "Views/Shared/_CookieConsentPartial.cshtml", "Views/Shared/_Layout.cshtml", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", @@ -660,7 +651,6 @@ "Views/Home/Index.cshtml", "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", - "Views/Shared/_CookieConsentPartial.cshtml", "Views/Shared/_Layout.cshtml", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", @@ -719,7 +709,6 @@ "Views/Home/Index.cshtml", "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", - "Views/Shared/_CookieConsentPartial.cshtml", "Views/Shared/_Layout.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico", @@ -777,7 +766,6 @@ "Views/Home/Index.cshtml", "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", - "Views/Shared/_CookieConsentPartial.cshtml", "Views/Shared/_Layout.cshtml", "Views/Shared/_LoginPartial.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", @@ -836,7 +824,6 @@ "Views/Home/Index.cshtml", "Views/Home/Privacy.cshtml", "Views/Shared/Error.cshtml", - "Views/Shared/_CookieConsentPartial.cshtml", "Views/Shared/_Layout.cshtml", "Views/Shared/_ValidationScriptsPartial.cshtml", "wwwroot/favicon.ico",