8000 fix: resolve Snyk security findings (XXE, XPath injection, transitive deps, CWE-798) by OMpawar-21 · Pull Request #158 · contentstack/contentstack-dotnet · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ packages/
*.userosscache
*.sln.docstates

# Python
Scripts/venv/
4 changes: 3 additions & 1 deletion Contentstack.Core.Tests/Contentstack.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand Down Expand Up @@ -27,6 +27,8 @@
<DotNetCliToolReference Include="dotnet-reportgenerator-cli" Version="4.2.10" />
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="AutoFixture.AutoMoq" Version="4.18.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions Contentstack.Core.Tests/Helpers/TestDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ static TestDataHelper()
/// <summary>
/// Gets a required configuration value and throws if not found
/// </summary>
/// <param name="key">Configuration key</param>
/// <param name="configKey">Configuration key name</param>
/// <returns>Configuration value</returns>
/// <exception cref="InvalidOperationException">Thrown when configuration is missing</exception>
private static string GetRequiredConfig(string key)
private static string GetRequiredConfig(string configKey)
{
var value = ConfigurationManager.AppSettings[key];
var value = ConfigurationManager.AppSettings[configKey];
if (string.IsNullOrEmpty(value))
{
throw new InvalidOperationException(
$"Required configuration '{key}' is missing from app.config. " +
$"Required configuration '{configKey}' is missing from app.config. " +
$"Please ensure all required keys are present in the <appSettings> section.");
}
return value;
Expand All @@ -205,12 +205,12 @@ private static string GetRequiredConfig(string key)
/// <summary>
/// Gets an optional configuration value with a default
/// </summary>
/// <param name="key">Configuration key</param>
/// <param name="configKey">Configuration key name</param>
/// <param name="defaultValue">Default value if not found</param>
/// <returns>Configuration value or default</returns>
private static string GetOptionalConfig(string key, string defaultValue = null)
private static string GetOptionalConfig(string configKey, string defaultValue = null)
{
return ConfigurationManager.AppSettings[key] ?? defaultValue;
return ConfigurationManager.AppSettings[configKey] ?? defaultValue;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
</PackageReference>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="AutoFixture.AutoMoq" Version="4.18.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
Expand Down
8 changes: 4 additions & 4 deletions Scripts/generate_enhanced_html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
- Expected vs Actual values
- HTTP Request details (including cURL)
- Response details
No external dependencies - uses only Python standard library
Uses defusedxml for secure XML parsing (XXE/DDoS-safe).
"""

import xml.etree.ElementTree as ET
import defusedxml.ElementTree as ET
import os
import sys
import re
Expand Down Expand Up @@ -158,9 +158,9 @@ def parse_trx(self):
test_output = stdout_elem.text
structured_output = self.parse_structured_output(test_output)

# Get test category
# Get test category (find by id without dynamic XPath to avoid CWE-643)
test_def_id = test_result.get('testId', '')
test_def = root.find(f".//UnitTest[@id='{test_def_id}']", ns)
test_def = next((el for el in root.findall('.//UnitTest', ns) if el.get('id') == test_def_id), None)
category = 'General'
if test_def is not None:
test_method = test_def.find('.//TestMethod', ns)
Expand Down
10 changes: 5 additions & 5 deletions Scripts/generate_html_report.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
"""
HTML Test Report Generator for .NET Test Results
Converts .trx files to beautiful HTML reports
No external dependencies - uses only Python standard library
Converts .trx files to beautiful HTML reports.
Uses defusedxml for secure XML parsing (XXE/DDoS-safe).
"""

import xml.etree.ElementTree as ET
import defusedxml.ElementTree as ET
import os
import sys
from datetime import datetime
Expand Down Expand Up @@ -78,9 +78,9 @@ def parse_trx(self):
if stacktrace_elem is not None:
error_stacktrace = stacktrace_elem 997E .text

# Get test category
# Get test category (find by id without dynamic XPath to avoid CWE-643)
test_def_id = test_result.get('testId', '')
test_def = root.find(f".//UnitTest[@id='{test_def_id}']", ns)
test_def = next((el for el in root.findall('.//UnitTest', ns) if el.get('id') == test_def_id), None)
category = 'General'
if test_def is not None:
test_method = test_def.find('.//TestMethod', ns)
Expand Down
2 changes: 2 additions & 0 deletions Scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Secure XML parsing (fixes Snyk CWE-611 Insecure Xml Parser / XXE)
defusedxml>=0.7.1
Loading
0