Skip to content

Commit

Permalink
Merge pull request #221 from Ed-MacDonald/develop
Browse files Browse the repository at this point in the history
RemoteReaderPlugin configuration option to skip Uri validation
  • Loading branch information
lilith committed Jun 28, 2017
2 parents 008a626 + 67ed589 commit 3200cb7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Plugins/RemoteReader/RemoteReaderPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ public class RemoteReaderPlugin : BuilderExtension, IPlugin, IVirtualImageProvid
/// </summary>
public int AllowedRedirects { get; set; }

/// <summary>
/// Optionally skip validation using Uri.IsWellFormedUriString() to prevent errors with some non-standard URLs in use
/// </summary>
public bool SkipUriValidation { get; set; }

protected string remotePrefix = "~/remote";
Config c;

public RemoteReaderPlugin() {
AllowedRedirects = 5;
SkipUriValidation = false;
try {
remotePrefix = Util.PathUtils.ResolveAppRelativeAssumeAppRelative(remotePrefix);
//Remote prefix must never end in a slash - remote.jpg syntax...
Expand All @@ -67,6 +74,7 @@ public class RemoteReaderPlugin : BuilderExtension, IPlugin, IVirtualImageProvid
c.Pipeline.RewriteDefaults += Pipeline_RewriteDefaults;
c.Pipeline.PostRewrite += Pipeline_PostRewrite;
AllowedRedirects = c.get("remoteReader.allowedRedirects",AllowedRedirects);
SkipUriValidation = c.get("remoteReader.skipUriValidation", SkipUriValidation);

return this;
}
Expand Down Expand Up @@ -225,7 +233,7 @@ public class RemoteReaderPlugin : BuilderExtension, IPlugin, IVirtualImageProvid
args.RemoteUrl = "http://" + ReplaceInLeadingSegment(virtualPath.Substring(remotePrefix.Length).TrimStart('/', '\\'), "_", ".");
args.RemoteUrl = Uri.EscapeUriString(args.RemoteUrl);
}
if (!Uri.IsWellFormedUriString(args.RemoteUrl, UriKind.Absolute))
if (!SkipUriValidation && !Uri.IsWellFormedUriString(args.RemoteUrl, UriKind.Absolute))
throw new ImageProcessingException("Invalid request! The specified Uri is invalid: " + args.RemoteUrl);
return args;
}
Expand Down

0 comments on commit 3200cb7

Please sign in to comment.