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

Fix security issues #14

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .Net Framework/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.preferCSharpExtension": true
}
95 changes: 48 additions & 47 deletions .Net Framework/src/AutoMapper/Handlers/FunctionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,77 +22,78 @@ public dynamic Run(JObject transform, JObject input)
{
if (parameters != null)
{
foreach (var item in parameters)
foreach (var item in from item in parameters
where !(item is JToken)
select item)
{
if (!(item is JToken))
if (item.StartsWith("$"))
if (item.StartsWith("$"))
{
if (!item.ToUpperInvariant().Contains("[{PARENT}]"))
{
if (!item.ToUpperInvariant().Contains("[{PARENT}]"))
var tokens = input.SelectTokens((string)item);
if (tokens != null && tokens.Any())
{
var tokens = input.SelectTokens((string)item);
if (tokens != null && tokens.Any())
foreach (var i in tokens)
{
foreach (var i in tokens)
if (i.Type == JTokenType.Null)
{
inputParam.Add(nullString);
}
else if (string.IsNullOrWhiteSpace(i.ToString()))
{
if (i.Type == JTokenType.Null)
{
if (Convert.ToBoolean(ignoreEmptyValue))
inputParam.Add(nullString);
}
else if (string.IsNullOrWhiteSpace(i.ToString()))
{
if (Convert.ToBoolean(ignoreEmptyValue))
inputParam.Add(nullString);
else
inputParam.Add(i.ToString());
}
else
{
inputParam.Add(i.ToString());
}

}
}
else
{
inputParam.Add(nullString);
else
{
inputParam.Add(i.ToString());
}

}
}
else
{
JContainer json;
json = input.Parent;
for (int i = 2; i < item.Split(new string[] { "[{parent}]" }, System.StringSplitOptions.None).Length; i++)
{
json = json.Parent;
}
JToken valueToken = json.SelectToken(item.Replace("[{parent}].", "").Replace("$.", ""));
if (valueToken != null)
inputParam.Add(nullString);
}
}
else
{
JContainer json;
json = input.Parent;
for (int i = 2; i < item.Split(new string[] { "[{parent}]" }, System.StringSplitOptions.None).Length; i++)
{
json = json.Parent;
}
JToken valueToken = json.SelectToken(item.Replace("[{parent}].", "").Replace("$.", ""));
if (valueToken != null)
{
if (valueToken.Type == JTokenType.Array || valueToken.Type == JTokenType.Object)
inputParam.Add(valueToken.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", ""));
else if (valueToken.Value<string>() != null)
{
if (valueToken.Type == JTokenType.Array || valueToken.Type == JTokenType.Object)
inputParam.Add(valueToken.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", ""));
else if (valueToken.Value<string>() != null)
if (string.IsNullOrWhiteSpace(valueToken.ToString()))
{
if (string.IsNullOrWhiteSpace(valueToken.ToString()))
{
if (Convert.ToBoolean(ignoreEmptyValue))
inputParam.Add(nullString);
else
inputParam.Add(valueToken.ToString());
}
if (Convert.ToBoolean(ignoreEmptyValue))
inputParam.Add(nullString);
else
{
inputParam.Add(valueToken.ToString());
}
}
else
inputParam.Add(nullString);
{
inputParam.Add(valueToken.ToString());
}
}
else
inputParam.Add(nullString);
}
else
inputParam.Add(nullString);
}
else
inputParam.Add(item);
}
else
inputParam.Add(item);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion .Net Framework/src/AutoMapper/JsonToJsonMapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<Version>4.3.0</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>10.0.1</Version>
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="System.Reflection.Primitives">
<Version>4.3.0</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<HintPath>..\..\packages\Microsoft.CodeAnalysis.Scripting.Common.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.Scripting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Expand Down Expand Up @@ -163,8 +163,8 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.4\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.3.3.4\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
Expand Down
4 changes: 2 additions & 2 deletions .Net Framework/test/JsonToJsonMapper.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net46" />
<package id="Microsoft.CodeAnalysis.Analyzers" version="3.3.4" targetFramework="net46" developmentDependency="true" />
<package id="Microsoft.CodeAnalysis.Common" version="2.8.2" targetFramework="net46" />
<package id="Microsoft.CodeAnalysis.CSharp" version="2.8.2" targetFramework="net46" />
<package id="Microsoft.CodeAnalysis.CSharp.Scripting" version="2.8.2" targetFramework="net46" />
<package id="Microsoft.CodeAnalysis.Scripting" version="2.8.2" targetFramework="net46" />
<package id="Microsoft.CodeAnalysis.Scripting.Common" version="2.8.2" targetFramework="net46" />
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net46" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net46" />
<package id="System.AppContext" version="4.3.0" targetFramework="net46" />
<package id="System.Collections" version="4.3.0" targetFramework="net46" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net46" />
Expand Down
Loading