Skip to content

Commit

Permalink
Merge pull request #1000 from Badgerati/develop
Browse files Browse the repository at this point in the history
v2.7.1
  • Loading branch information
Badgerati authored Jul 21, 2022
2 parents eee125e + f4db3d4 commit 38ef2ce
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
10 changes: 10 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release Notes

## v2.7.1

```plain
### Bugs
* #990: Fix SMTP attachment name parsing, when the name contains a space
### Security
* #997: Fix an XSS exploit on the default error pages
```

## v2.7.0

```plain
Expand Down
14 changes: 12 additions & 2 deletions src/Listener/PodeSmtpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ private Hashtable ParseHeaders(string value)

var lines = value.Split(new string[] { PodeHelpers.NEW_LINE }, StringSplitOptions.None);
var match = default(Match);
var previousHeader = string.Empty;

foreach (var line in lines)
{
Expand All @@ -317,8 +318,17 @@ private Hashtable ParseHeaders(string value)
match = Regex.Match(line, "^(?<name>.*?)\\:\\s+(?<value>.*?)$");
if (match.Success)
{
previousHeader = match.Groups["name"].Value;
headers.Add(match.Groups["name"].Value, match.Groups["value"].Value);
}
else
{
match = Regex.Match(line, "^(?<name>.*?)\\:\\s+");
if (!match.Success)
{
headers[previousHeader] += line;
}
}

// boundary line
match = Regex.Match(line, "^\\s*boundary=\"?(?<boundary>.+?)\"?$");
Expand Down Expand Up @@ -375,8 +385,8 @@ private void ParseBoundary()
var contentDisposition = $"{headers["Content-Disposition"]}";
if (!string.IsNullOrEmpty(contentDisposition) && contentDisposition.ToLowerInvariant().Contains("attachment"))
{
var match = Regex.Match(contentType, "name=\"?(?<name>.+)\"?");
var name = match.Groups["name"].Value;
var match = Regex.Match(contentType, "name=(?<name>.+)");
var name = match.Groups["name"].Value.Trim('"');

var stream = new MemoryStream();
stream.Write(bodyBytes, 0, bodyBytes.Length);
Expand Down
24 changes: 12 additions & 12 deletions src/Private/Responses.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Show-PodeErrorPage
{
param (
param(
[Parameter()]
[int]
$Code,
Expand Down Expand Up @@ -29,22 +29,22 @@ function Show-PodeErrorPage
$ex = $null
if (!(Test-PodeIsEmpty $Exception) -and $PodeContext.Server.Web.ErrorPages.ShowExceptions) {
$ex = @{
'Message' = [System.Web.HttpUtility]::HtmlEncode($Exception.Exception.Message);
'StackTrace' = [System.Web.HttpUtility]::HtmlEncode($Exception.ScriptStackTrace);
'Line' = [System.Web.HttpUtility]::HtmlEncode($Exception.InvocationInfo.PositionMessage);
'Category' = [System.Web.HttpUtility]::HtmlEncode($Exception.CategoryInfo.ToString());
Message = [System.Web.HttpUtility]::HtmlEncode($Exception.Exception.Message)
StackTrace = [System.Web.HttpUtility]::HtmlEncode($Exception.ScriptStackTrace)
Line = [System.Web.HttpUtility]::HtmlEncode($Exception.InvocationInfo.PositionMessage)
Category = [System.Web.HttpUtility]::HtmlEncode($Exception.CategoryInfo.ToString())
}
}

# setup the data object for dynamic pages
$data = @{
'Url' = (Get-PodeUrl);
'Status' = @{
'Code' = $Code;
'Description' = $Description;
};
'Exception' = $ex;
'ContentType' = $errorPage.ContentType;
Url = [System.Web.HttpUtility]::HtmlEncode((Get-PodeUrl))
Status = @{
Code = $Code
Description = $Description
}
Exception = $ex
ContentType = $errorPage.ContentType
}

# write the error page to the stream
Expand Down

0 comments on commit 38ef2ce

Please sign in to comment.