-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DNN-10601: preventing handling external URLs in image handler.
- Loading branch information
Showing
8 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
DNN Platform/Tests/DNN.Integration.Test.Framework/Helpers/PortalAliasHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// DotNetNuke® - http://www.dnnsoftware.com | ||
// Copyright (c) 2002-2018, DNN Corp. | ||
// All Rights Reserved | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using DotNetNuke.Entities.Portals; | ||
|
||
namespace DNN.Integration.Test.Framework.Helpers | ||
{ | ||
public class PortalAliasHelper | ||
{ | ||
public static PortalAliasInfo GetPrimaryPortalAlias(int portalId = 0) | ||
{ | ||
return DatabaseHelper.ExecuteStoredProcedure<PortalAliasInfo>("GetPortalAliases").First(p => p.PortalID == portalId && p.IsPrimary); | ||
} | ||
|
||
public static IEnumerable<PortalAliasInfo> GetPortalAliaes(int portalId = 0) | ||
{ | ||
return DatabaseHelper.ExecuteStoredProcedure<PortalAliasInfo>("GetPortalAliases").Where(p => p.PortalID == portalId); | ||
} | ||
|
||
public static IEnumerable<PortalAliasInfo> GetAllPortalAliaes() | ||
{ | ||
return DatabaseHelper.ExecuteStoredProcedure<PortalAliasInfo>("GetPortalAliases"); | ||
} | ||
|
||
public static void AddPortalAlias(PortalAliasInfo portal) | ||
{ | ||
DatabaseHelper.ExecuteStoredProcedure("AddPortalAlias", | ||
portal.PortalID, | ||
portal.HTTPAlias, | ||
portal.CultureCode, | ||
portal.Skin, | ||
portal.BrowserType, | ||
portal.IsPrimary, | ||
-1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
DNN Platform/Tests/DotNetNuke.Tests.Integration/Tests/Library/ImageHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// DotNetNuke® - http://www.dnnsoftware.com | ||
// Copyright (c) 2002-2018, DNN Corp. | ||
// All Rights Reserved | ||
|
||
using System.Linq; | ||
using DNN.Integration.Test.Framework; | ||
using DNN.Integration.Test.Framework.Helpers; | ||
using DotNetNuke.Entities.Portals; | ||
using NUnit.Framework; | ||
|
||
namespace DotNetNuke.Tests.Integration.Tests.Library | ||
{ | ||
[TestFixture] | ||
public class ImageHandlerTests : IntegrationTestBase | ||
{ | ||
// we assume this GIF image exists in all DNN sites and it shouldn't be PNG | ||
private const string HandlerPath = "/DnnImageHandler.ashx?mode=file&w=1&url={0}/images/1x1.GIF"; | ||
|
||
[Test] | ||
public void Using_Image_Handler_For_Foreign_Site_ShouldFail() | ||
{ | ||
var session = WebApiTestHelper.GetAnnonymousConnector(); | ||
var relativeUrl = string.Format(HandlerPath, "https://google.com"); | ||
|
||
var response = session.GetContent(relativeUrl).Content.ReadAsStringAsync().Result; | ||
Assert.IsTrue(response.StartsWith("�PNG\r\n"), $"Content = {response}"); | ||
} | ||
|
||
[Test] | ||
public void Using_Image_Handler_For_Main_Alias_ShouldPass() | ||
{ | ||
var session = WebApiTestHelper.GetAnnonymousConnector(); | ||
var relativeUrl = string.Format(HandlerPath, AppConfigHelper.SiteUrl); | ||
|
||
var response = session.GetContent(relativeUrl).Content.ReadAsStringAsync().Result; | ||
Assert.IsTrue(response.StartsWith("GIF89a"), $"Content = {response}"); | ||
} | ||
|
||
[Test] | ||
public void Using_Image_Handler_From_All_Alias_ShouldPass() | ||
{ | ||
PortalAliasInfo pai; | ||
var aliases = PortalAliasHelper.GetPortalAliaes().ToList(); | ||
if (aliases.Count == 1) | ||
{ | ||
var primary = aliases.First(); | ||
pai = new PortalAliasInfo | ||
{ | ||
PortalID = primary.PortalID, | ||
HTTPAlias = "my-" + primary.HTTPAlias, | ||
CultureCode = primary.CultureCode, | ||
Skin = primary.Skin, | ||
BrowserType = primary.BrowserType, | ||
IsPrimary = false, | ||
|
||
}; | ||
} | ||
else | ||
{ | ||
pai = aliases.First(a => a.PortalAliasID > 1); | ||
} | ||
|
||
var session = WebApiTestHelper.GetAnnonymousConnector(); | ||
aliases = PortalAliasHelper.GetPortalAliaes().ToList(); | ||
foreach (var alias in aliases) | ||
{ | ||
var relativeUrl = string.Format(HandlerPath, AppConfigHelper.SiteUrl); | ||
var absoluteUrl = $"http://{alias.HTTPAlias}{relativeUrl}"; | ||
LogText("Getting image from " + absoluteUrl); | ||
|
||
var response = session.GetContent(absoluteUrl).Content.ReadAsStringAsync().Result; | ||
Assert.IsTrue(response.StartsWith("GIF89a"), $"Url: {absoluteUrl} / Content = {response}"); | ||
} | ||
} | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
DNN Platform/Tests/DotNetNuke.Tests.Integration/Tests/Security/AuthCookieTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters