Skip to content

Commit fb91e75

Browse files
authored
Adding an allowlist for EPR links for the image directive (#1651)
* adding an allowlist for epr links * review feedback
1 parent 7712e71 commit fb91e75

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Elastic.Markdown/Myst/Directives/Image/ImageBlock.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class ImageBlock(DirectiveBlockParser parser, ParserContext context)
6868

6969
public string? Label { get; private set; }
7070

71+
private static readonly HashSet<string> AllowedUriHosts = ["epr.elastic.co"];
72+
7173
public override void FinalizeAndValidate(ParserContext context)
7274
{
7375
Label = Prop("label", "name");
@@ -98,7 +100,9 @@ private void ExtractImageUrl(ParserContext context)
98100

99101
if (Uri.TryCreate(imageUrl, UriKind.Absolute, out var uri) && uri.Scheme.StartsWith("http"))
100102
{
101-
this.EmitWarning($"{Directive} is using an external URI: {uri} ");
103+
if (!AllowedUriHosts.Contains(uri.Host))
104+
this.EmitWarning($"{Directive} is using an external URI: {uri} ");
105+
102106
Found = true;
103107
ImageUrl = imageUrl;
104108
return;

0 commit comments

Comments
 (0)