Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteReaderPlugin configuration option to skip Uri validation #221

Merged
merged 5 commits into from
Jun 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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