Browse Source

Revert "Extended remote file reader to handle extensionless image urls and querystring parameters for remote URLs"

This reverts commit d24a99bf2b [formerly f1980db0fd571a80283c1698380ca3f672903b12].


Former-commit-id: c1ca84b5ef133787529ecd0c8b5a53d63c74d2ef
pull/17/head
aka Torgon Woodget 13 years ago
committed by James South
parent
commit
5e4be15324
  1. 11
      src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs
  2. 16
      src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs
  3. 5
      src/ImageProcessor.Web/NET45/Helpers/RemoteFile.cs
  4. 50
      src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
  5. 7
      src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
  6. 6
      src/ImageProcessor.Web/NET45/packages.config

11
src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs

@ -121,17 +121,6 @@ namespace ImageProcessor.Web.Config
} }
} }
/// <summary>
///
/// </summary>
public ImageSecuritySection.SafeUrl[] RemoteFileWhiteListExtensions
{
get
{
return GetImageSecuritySection().WhiteList.Cast<ImageSecuritySection.SafeUrl>().ToArray();
}
}
/// <summary> /// <summary>
/// Gets a value indicating whether the current application is allowed to download remote files. /// Gets a value indicating whether the current application is allowed to download remote files.
/// </summary> /// </summary>

16
src/ImageProcessor.Web/NET45/Config/ImageSecuritySection.cs

@ -178,22 +178,6 @@ namespace ImageProcessor.Web.Config
set { this["url"] = value; } set { this["url"] = value; }
} }
[ConfigurationProperty("extensionLess", DefaultValue = false, IsRequired = false)]
public bool ExtensionLess
{
get { return (bool)this["extensionLess"]; }
set { this["extensionLess"] = value; }
}
[ConfigurationProperty("imageFormat", DefaultValue = "", IsRequired = false)]
public string ImageFormat
{
get { return (string)this["imageFormat"]; }
set { this["imageFormat"] = value; }
}
} }
} }
} }

5
src/ImageProcessor.Web/NET45/Helpers/RemoteFile.cs

@ -48,11 +48,6 @@ namespace ImageProcessor.Web.Helpers
/// </summary> /// </summary>
private static readonly Uri[] RemoteFileWhiteList = ImageProcessorConfig.Instance.RemoteFileWhiteList; private static readonly Uri[] RemoteFileWhiteList = ImageProcessorConfig.Instance.RemoteFileWhiteList;
/// <summary>
/// The white-list of url[s] from which to download remote files.
/// </summary>
public static readonly ImageSecuritySection.SafeUrl[] RemoteFileWhiteListExtensions = ImageProcessorConfig.Instance.RemoteFileWhiteListExtensions;
/// <summary> /// <summary>
/// The length of time, in milliseconds, that a remote file download attempt can last before timing out. /// The length of time, in milliseconds, that a remote file download attempt can last before timing out.
/// </summary> /// </summary>

50
src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs

@ -5,11 +5,6 @@
// </copyright> // </copyright>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using System.Linq;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text;
namespace ImageProcessor.Web.HttpModules namespace ImageProcessor.Web.HttpModules
{ {
#region Using #region Using
@ -182,10 +177,6 @@ namespace ImageProcessor.Web.HttpModules
string requestPath = string.Empty; string requestPath = string.Empty;
string queryString = string.Empty; string queryString = string.Empty;
bool validExtensionLessUrl = false;
string urlParameters = "";
string extensionLessExtension = "";
if (isRemote) if (isRemote)
{ {
// We need to split the querystring to get the actual values we want. // We need to split the querystring to get the actual values we want.
@ -203,25 +194,10 @@ namespace ImageProcessor.Web.HttpModules
requestPath = paths[0]; requestPath = paths[0];
if (paths.Count() > 2) if (paths.Length > 1)
{
queryString = paths[2];
urlParameters = paths[1];
}
else if (paths.Length > 1)
{ {
queryString = paths[1]; queryString = paths[1];
} }
validExtensionLessUrl = RemoteFile.RemoteFileWhiteListExtensions.Any(
x => x.ExtensionLess == true && requestPath.StartsWith(x.Url.AbsoluteUri));
if (validExtensionLessUrl)
{
extensionLessExtension = RemoteFile.RemoteFileWhiteListExtensions.First(
x => x.ExtensionLess == true && requestPath.StartsWith(x.Url.AbsoluteUri)).ImageFormat;
}
} }
} }
else else
@ -231,31 +207,11 @@ namespace ImageProcessor.Web.HttpModules
} }
// Only process requests that pass our sanitizing filter. // Only process requests that pass our sanitizing filter.
if ((ImageUtils.IsValidImageExtension(requestPath) || validExtensionLessUrl ) && !string.IsNullOrWhiteSpace(queryString)) if (ImageUtils.IsValidImageExtension(requestPath) && !string.IsNullOrWhiteSpace(queryString))
{ {
string fullPath = string.Format("{0}?{1}", requestPath, queryString); string fullPath = string.Format("{0}?{1}", requestPath, queryString);
string imageName = Path.GetFileName(requestPath); string imageName = Path.GetFileName(requestPath);
if (validExtensionLessUrl && !string.IsNullOrWhiteSpace(extensionLessExtension))
{
fullPath = requestPath;
if (!string.IsNullOrWhiteSpace(urlParameters))
{
//TODO: Add hash for querystring parameters
HashAlgorithm algorithm = MD5.Create(); // SHA1.Create()
var hashCode = algorithm.ComputeHash(Encoding.UTF8.GetBytes(urlParameters));
StringBuilder sb = new StringBuilder();
foreach (byte b in hashCode)
sb.Append(b.ToString("X2"));
imageName += sb.ToString();
fullPath += sb.ToString();
}
imageName += "." + extensionLessExtension;
fullPath += extensionLessExtension + "?" + queryString;
}
// Create a new cache to help process and cache the request. // Create a new cache to help process and cache the request.
DiskCache cache = new DiskCache(request, requestPath, fullPath, imageName, isRemote); DiskCache cache = new DiskCache(request, requestPath, fullPath, imageName, isRemote);
@ -295,7 +251,7 @@ namespace ImageProcessor.Web.HttpModules
{ {
if (isRemote) if (isRemote)
{ {
Uri uri = new Uri(requestPath + "?" + urlParameters); Uri uri = new Uri(requestPath);
RemoteFile remoteFile = new RemoteFile(uri, false); RemoteFile remoteFile = new RemoteFile(uri, false);

7
src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj

@ -11,8 +11,6 @@
<AssemblyName>ImageProcessor.Web</AssemblyName> <AssemblyName>ImageProcessor.Web</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\..\..\..\..\TFS\ActiMeet\ActiMeet2\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -33,10 +31,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Community.CsharpSqlite"> <Reference Include="Community.CsharpSqlite">
<HintPath>..\..\..\..\..\..\..\..\TFS\ActiMeet\ActiMeet2\packages\Csharp-Sqlite.3.7.7.1\lib\net40\Community.CsharpSqlite.dll</HintPath> <HintPath>..\..\packages\Csharp-Sqlite.3.7.7.1\lib\net40\Community.CsharpSqlite.dll</HintPath>
</Reference> </Reference>
<Reference Include="Community.CsharpSqlite.SQLiteClient"> <Reference Include="Community.CsharpSqlite.SQLiteClient">
<HintPath>..\..\..\..\..\..\..\..\TFS\ActiMeet\ActiMeet2\packages\Csharp-Sqlite.3.7.7.1\lib\net40\Community.CsharpSqlite.SQLiteClient.dll</HintPath> <HintPath>..\..\packages\Csharp-Sqlite.3.7.7.1\lib\net40\Community.CsharpSqlite.SQLiteClient.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
@ -77,7 +75,6 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">

6
src/ImageProcessor.Web/NET45/packages.config

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages >
<package id="Csharp-Sqlite" version="3.7.7.1" targetFramework="net45" /> <package id="Csharp-Sqlite" version="3.7.7.1" targetFramework="net40" />
<package id="sqlite-net" version="1.0.7" targetFramework="net45" /> <package id="sqlite-net" version="1.0.7" targetFramework="net40" />
</packages> </packages>
Loading…
Cancel
Save