From 2b0cb2241df2faafe091cbf7bb1160e74ccd7e1d Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Mon, 17 Feb 2025 11:55:59 +0100 Subject: [PATCH 1/2] Remove ExternalLinkHosts validation We still validate mailto links, these may only link to elastic.co addresses (hardcoded). --- .../IO/Configuration/ConfigurationFile.cs | 10 +++------- .../Myst/InlineParsers/DiagnosticLinkInlineParser.cs | 6 ++---- tests/authoring/Inline/InlineLinks.fs | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs b/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs index 6e8f24186..e6352591b 100644 --- a/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs +++ b/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs @@ -26,7 +26,6 @@ public record ConfigurationFile : DocumentationFile public HashSet Files { get; } = new(StringComparer.OrdinalIgnoreCase); public HashSet ImplicitFolders { get; } = new(StringComparer.OrdinalIgnoreCase); public Glob[] Globs { get; } = []; - public HashSet ExternalLinkHosts { get; } = new(StringComparer.OrdinalIgnoreCase) { "elastic.co", "github.com", "localhost", }; private readonly Dictionary _substitutions = new(StringComparer.OrdinalIgnoreCase); public IReadOnlyDictionary Substitutions => _substitutions; @@ -80,12 +79,6 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon case "subs": _substitutions = ReadDictionary(entry); break; - case "external_hosts": - var hosts = ReadStringArray(entry) - .ToArray(); - foreach (var host in hosts) - ExternalLinkHosts.Add(host); - break; case "toc": if (depth > 1) { @@ -97,6 +90,9 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon TableOfContents = entries; break; + case "external_hosts": + EmitWarning($"{key} has been deprecated and will be removed", entry.Key); + break; default: EmitWarning($"{key} is not a known configuration", entry.Key); break; diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index b75885d89..a350aa533 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -143,13 +143,11 @@ private bool ValidateExternalUri(LinkInline link, InlineProcessor processor, Par return false; var baseDomain = uri.Host == "localhost" ? "localhost" : string.Join('.', uri.Host.Split('.')[^2..]); - if (!context.Configuration.ExternalLinkHosts.Contains(baseDomain)) + if (uri.Scheme == "mailto" && baseDomain != "elastic.co") { processor.EmitWarning( link, - $"External URI '{uri}' is not allowed. Add '{baseDomain}' to the " + - $"'external_hosts' list in the configuration file '{context.Configuration.SourceFile}' " + - "to allow links to this domain." + $"mailto links should be to elastic.co domains. Found {uri.Host} in {link.Url}. " ); } diff --git a/tests/authoring/Inline/InlineLinks.fs b/tests/authoring/Inline/InlineLinks.fs index 10a9d6285..32e936ce0 100644 --- a/tests/authoring/Inline/InlineLinks.fs +++ b/tests/authoring/Inline/InlineLinks.fs @@ -45,4 +45,4 @@ type ``inline link with mailto not allowed external host`` () = let ``has no errors`` () = markdown |> hasNoErrors [] - let ``has warning`` () = markdown |> hasWarning "External URI 'mailto:fake-email@somehost.co' is not allowed." + let ``has warning`` () = markdown |> hasWarning "mailto links should be to elastic.co domains." From 4159400f42be89c5c8f027594529b149d96f868b Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Mon, 17 Feb 2025 12:20:49 +0100 Subject: [PATCH 2/2] remove external_hosts from docset.yml --- docs/docset.yml | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/docs/docset.yml b/docs/docset.yml index 635e68457..e20b16157 100644 --- a/docs/docset.yml +++ b/docs/docset.yml @@ -1,32 +1,6 @@ project: 'doc-builder' cross_links: - docs-content -# docs-builder will warn for links to external hosts not declared here -external_hosts: - - slack.com - - mystmd.org - - microsoft.com - - azure.com - - mistral.ai - - amazon.com - - python.org - - cohere.com - - docker.com - - langchain.com - - nodejs.org - - yarnpkg.com - - react.dev - - palletsprojects.com - - google.com - - checkvist.com - - commonmark.org - - github.io - - github.com - - pandoc.org - - atlassian.net - - elastic.dev - - visualstudio.com - - wikipedia.org exclude: - '_*.md' subs: