Skip to content

Commit 78631a0

Browse files
committed
minor fixes and import sanitization
1 parent f15a705 commit 78631a0

16 files changed

Lines changed: 214 additions & 150 deletions

File tree

‎Cervantes.CORE/ViewModel/UserEditViewModel.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ public class UserEditViewModel
4040
public Guid? ClientId { get; set; }
4141
public string ImagePath { get; set; }
4242

43-
public bool LockoutEnabled { get; set; }
43+
public bool Lockout { get; set; }
4444
public bool TwoFactorEnabled { get; set; }
4545
}

‎Cervantes.DAL/Cervantes.DAL.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16+
<PackageReference Include="HtmlSanitizer" Version="8.0.811" />
1617
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
1718
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
1819
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.1" />

‎Cervantes.DAL/DataInitializer.cs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using Microsoft.AspNetCore.Identity;
44
using System.Linq;
55
using System.Security.Cryptography;
6+
using System.Web;
67
using System.Xml;
78
using Cervantes.Contracts;
89
using Cervantes.CORE.Entities;
10+
using Ganss.Xss;
911
using Microsoft.Extensions.Logging;
1012
using Task = System.Threading.Tasks.Task;
1113

@@ -35,7 +37,9 @@ public static void SeedCwe(ICweManager cweManager, string cweFile)
3537
xmlDocument.Load(cweFile);
3638

3739
XmlNodeList weaknessNodes = xmlDocument.GetElementsByTagName("Weakness");
38-
40+
var sanitizer = new HtmlSanitizer();
41+
sanitizer.AllowedSchemes.Add("data");
42+
3943
foreach (XmlNode weaknessNode in weaknessNodes)
4044
{
4145
string id = weaknessNode.Attributes["ID"].Value;
@@ -47,8 +51,8 @@ public static void SeedCwe(ICweManager cweManager, string cweFile)
4751

4852
Cwe cwe = new Cwe();
4953
cwe.Id = Convert.ToInt32(id);
50-
cwe.Name = name;
51-
cwe.Description = desc;
54+
cwe.Name = sanitizer.Sanitize(HttpUtility.HtmlDecode(name));
55+
cwe.Description = sanitizer.Sanitize(HttpUtility.HtmlDecode(desc));
5256

5357
cweManager.Add(cwe);
5458
cweManager.Context.SaveChanges();

‎Cervantes.IFR/Cervantes.IFR.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PackageReference Include="CsvHelper" Version="30.1.0" />
2020
<PackageReference Include="Html2JiraMarkup" Version="1.0.4" />
2121
<PackageReference Include="HtmlAgilityPack" Version="1.11.58" />
22+
<PackageReference Include="HtmlSanitizer" Version="8.0.811" />
2223
<PackageReference Include="MailKit" Version="4.3.0" />
2324
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
2425
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />

‎Cervantes.IFR/Parsers/CSV/CsvParser.cs‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
using System.IO;
44
using System.Linq;
55
using System.Security.Claims;
6+
using System.Web;
67
using Cervantes.Contracts;
78
using Cervantes.CORE;
89
using Cervantes.CORE.Entities;
910
using CsvHelper;
1011
using CsvHelper.Configuration;
12+
using Ganss.Xss;
1113

1214
namespace Cervantes.IFR.Parsers.CSV;
1315

@@ -31,6 +33,9 @@ public void Parse(Guid? project, string user, string path)
3133
{
3234
Delimiter = ";"
3335
};
36+
var sanitizer = new HtmlSanitizer();
37+
sanitizer.AllowedSchemes.Add("data");
38+
3439
using (var reader = new StreamReader(path))
3540
using (var csv = new CsvReader(reader, config))
3641
{
@@ -44,28 +49,28 @@ public void Parse(Guid? project, string user, string path)
4449
foreach (var vul in records)
4550
{
4651
Vuln vuln = new Vuln();
47-
vuln.Name = vul.Name == "" ? "No Name" : vul.Name;
52+
vuln.Name = vul.Name == "" ? "No Name" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Name));
4853

4954
vuln.Template = vul.Template.HasValue && vul.Template.Value;
50-
vuln.cve = vul.CVE == "" ? "None" : vul.CVE;
51-
vuln.Description = vul.Description == "" ? "No Data" : vul.Description;
52-
vuln.Impact = vul.Impact == "" ? "No Data" : vul.Impact;
55+
vuln.cve = vul.CVE == "" ? "None" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.CVE));
56+
vuln.Description = vul.Description == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Description));
57+
vuln.Impact = vul.Impact == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Impact));
5358
vuln.Risk = vul.Risk ?? VulnRisk.Info;
5459
vuln.Status = vul.Status ?? VulnStatus.Open;
5560
vuln.CreatedDate = DateTime.Now.ToUniversalTime();
5661
vuln.JiraCreated = false;
57-
vuln.Remediation = vul.Remediation == "" ? "No Data" : vul.Remediation;
62+
vuln.Remediation = vul.Remediation == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Remediation));
5863
vuln.RemediationPriority = vul.RemediationPriority ?? RemediationPriority.Low;
5964
vuln.RemediationComplexity = vul.RemediationComplexity ?? RemediationComplexity.Low;
60-
vuln.OWASPRisk = vul.OwaspRisk == "" ? "No Data" : vul.OwaspRisk;
61-
vuln.OWASPImpact = vul.OwaspImpact == "" ? "No Data" : vul.OwaspImpact;
62-
vuln.OWASPLikehood = vul.OwaspLikehood == "" ? "No Data" : vul.OwaspLikehood;
63-
vuln.OWASPVector = vul.OwaspVector == "" ? "No Data" : vul.OwaspVector;
65+
vuln.OWASPRisk = vul.OwaspRisk == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspRisk));
66+
vuln.OWASPImpact = vul.OwaspImpact == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspImpact));
67+
vuln.OWASPLikehood = vul.OwaspLikehood == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspLikehood));
68+
vuln.OWASPVector = vul.OwaspVector == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspVector));
6469
vuln.ProjectId = project;
65-
vuln.ProofOfConcept = vul.Poc == "" ? "No Data" : vul.Poc;
70+
vuln.ProofOfConcept = vul.Poc == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Poc));
6671
vuln.UserId = user;
6772
vuln.CVSS3 = vul.CVSS3 ?? 0;
68-
vuln.CVSSVector = vul.CVSSVector == "" ? "No Data" : vul.CVSSVector;
73+
vuln.CVSSVector = vul.CVSSVector == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.CVSSVector));
6974
var cat = vulnCategoryManager.GetByName(vul.VulnCategory);
7075
if (cat != null)
7176
{
@@ -86,28 +91,28 @@ public void Parse(Guid? project, string user, string path)
8691
foreach (var vul in records)
8792
{
8893
Vuln vuln = new Vuln();
89-
vuln.Name = vul.Name == "" ? "No Name" : vul.Name;
94+
vuln.Name = vul.Name == "" ? "No Name" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Name));
9095

9196
vuln.Template = vul.Template.HasValue && vul.Template.Value;
92-
vuln.cve = vul.CVE == "" ? "None" : vul.CVE;
93-
vuln.Description = vul.Description == "" ? "No Data" : vul.Description;
94-
vuln.Impact = vul.Impact == "" ? "No Data" : vul.Impact;
97+
vuln.cve = vul.CVE == "" ? "None" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.CVE));
98+
vuln.Description = vul.Description == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Description));
99+
vuln.Impact = vul.Impact == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Impact));
95100
vuln.Risk = vul.Risk ?? VulnRisk.Info;
96101
vuln.Status = vul.Status ?? VulnStatus.Open;
97102
vuln.CreatedDate = DateTime.Now.ToUniversalTime();
98103
vuln.JiraCreated = false;
99-
vuln.Remediation = vul.Remediation == "" ? "No Data" : vul.Remediation;
104+
vuln.Remediation = vul.Remediation == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.Remediation));
100105
vuln.RemediationPriority = vul.RemediationPriority ?? RemediationPriority.Low;
101106
vuln.RemediationComplexity = vul.RemediationComplexity ?? RemediationComplexity.Low;
102-
vuln.OWASPRisk = vul.OwaspRisk == "" ? "No Data" : vul.OwaspRisk;
103-
vuln.OWASPImpact = vul.OwaspImpact == "" ? "No Data" : vul.OwaspImpact;
104-
vuln.OWASPLikehood = vul.OwaspLikehood == "" ? "No Data" : vul.OwaspLikehood;
105-
vuln.OWASPVector = vul.OwaspVector == "" ? "No Data" : vul.OwaspVector;
107+
vuln.OWASPRisk = vul.OwaspRisk == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspRisk));
108+
vuln.OWASPImpact = vul.OwaspImpact == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspImpact));
109+
vuln.OWASPLikehood = vul.OwaspLikehood == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspLikehood));
110+
vuln.OWASPVector = vul.OwaspVector == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.OwaspVector));
106111
vuln.ProjectId = null;
107112
vuln.ProofOfConcept = vul.Poc == "" ? "No Data" : vul.Poc;
108113
vuln.UserId = user;
109114
vuln.CVSS3 = vul.CVSS3 ?? 0;
110-
vuln.CVSSVector = vul.CVSSVector == "" ? "No Data" : vul.CVSSVector;
115+
vuln.CVSSVector = vul.CVSSVector == "" ? "No Data" : sanitizer.Sanitize(HttpUtility.HtmlDecode(vul.CVSSVector));
111116
var cat = vulnCategoryManager.GetByName(vul.VulnCategory);
112117
if (cat != null)
113118
{

‎Cervantes.IFR/Parsers/Nessus/NessusParser.cs‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22
using System.Globalization;
33
using System.Linq;
4+
using System.Web;
45
using System.Xml;
56
using Cervantes.Contracts;
67
using Cervantes.CORE;
78
using Cervantes.CORE.Entities;
9+
using Ganss.Xss;
810

911
namespace Cervantes.IFR.Parsers.Nessus;
1012

@@ -28,7 +30,8 @@ public void Parse(Guid? project, string user, string path)
2830
doc.Load(path);
2931

3032
XmlNodeList hosts = doc.GetElementsByTagName("ReportHost");
31-
33+
var sanitizer = new HtmlSanitizer();
34+
sanitizer.AllowedSchemes.Add("data");
3235
if (project != null)
3336
{
3437
var pro = projectManager.GetById((Guid) project);
@@ -56,8 +59,8 @@ public void Parse(Guid? project, string user, string path)
5659
{
5760
UserId = user,
5861
ProjectId = project,
59-
Name = hostName,
60-
Description = "<p>Host created from Nessus Scan Import</p>" + "<p>OS: "+ os +"</p>"+ "<p>Host Ip: "+ hostIp +"</p>",
62+
Name = sanitizer.Sanitize(HttpUtility.HtmlDecode(hostName)),
63+
Description = "<p>Host created from Nessus Scan Import</p>" + "<p>OS: "+ sanitizer.Sanitize(HttpUtility.HtmlDecode(os)) +"</p>"+ "<p>Host Ip: "+ sanitizer.Sanitize(HttpUtility.HtmlDecode(hostIp)) +"</p>",
6164
Type = TargetType.Hostname
6265
};
6366

@@ -96,7 +99,7 @@ public void Parse(Guid? project, string user, string path)
9699
var vulNum = vulnManager.GetAll().Count(x => x.ProjectId == project && x.Template == false) + 1;
97100
vuln.FindingId = pro.FindingsId + "-" + vulNum.ToString("D2");
98101
vuln.Template = false;
99-
vuln.Name = pluginName;
102+
vuln.Name = sanitizer.Sanitize(HttpUtility.HtmlDecode(pluginName));
100103
vuln.CreatedDate = DateTime.Now.ToUniversalTime();
101104
vuln.UserId = user;
102105
vuln.ProjectId = project;
@@ -120,10 +123,10 @@ public void Parse(Guid? project, string user, string path)
120123
break;
121124
}
122125
vuln.Status = VulnStatus.Open;
123-
vuln.cve = cve;
124-
vuln.Description = "<p>"+description+"</p>"+ "<p>References: " +"<p>"+refrences+"</p>";
125-
vuln.ProofOfConcept = pluginOutput;
126-
vuln.Impact = impact;
126+
vuln.cve = sanitizer.Sanitize(HttpUtility.HtmlDecode(cve));
127+
vuln.Description = "<p>"+sanitizer.Sanitize(HttpUtility.HtmlDecode(description))+"</p>"+ "<p>References: " +"<p>"+sanitizer.Sanitize(HttpUtility.HtmlDecode(refrences))+"</p>";
128+
vuln.ProofOfConcept = sanitizer.Sanitize(HttpUtility.HtmlDecode(pluginOutput));
129+
vuln.Impact = sanitizer.Sanitize(HttpUtility.HtmlDecode(impact));
127130
if (cvss != "")
128131
{
129132
vuln.CVSS3 = float.Parse(cvss,CultureInfo.InvariantCulture);
@@ -133,8 +136,8 @@ public void Parse(Guid? project, string user, string path)
133136
vuln.CVSS3 = 0;
134137
}
135138

136-
vuln.CVSSVector = cvssVector;
137-
vuln.Remediation = solution;
139+
vuln.CVSSVector = sanitizer.Sanitize(HttpUtility.HtmlDecode(cvssVector));
140+
vuln.Remediation = sanitizer.Sanitize(HttpUtility.HtmlDecode(solution));
138141
vuln.RemediationComplexity = RemediationComplexity.Low;
139142
vuln.RemediationPriority = RemediationPriority.Low;
140143
vuln.JiraCreated = false;
@@ -205,7 +208,7 @@ public void Parse(Guid? project, string user, string path)
205208

206209
var vuln = new Vuln();
207210
vuln.Template = false;
208-
vuln.Name = pluginName;
211+
vuln.Name = sanitizer.Sanitize(HttpUtility.HtmlDecode(pluginName));
209212
vuln.CreatedDate = DateTime.Now.ToUniversalTime();
210213
vuln.UserId = user;
211214
vuln.ProjectId = null;
@@ -229,10 +232,10 @@ public void Parse(Guid? project, string user, string path)
229232
break;
230233
}
231234
vuln.Status = VulnStatus.Open;
232-
vuln.cve = cve;
233-
vuln.Description = "<p>"+description+"</p>"+ "<p>References: " +"<p>"+refrences+"</p>";
234-
vuln.ProofOfConcept = pluginOutput;
235-
vuln.Impact = impact;
235+
vuln.cve = sanitizer.Sanitize(HttpUtility.HtmlDecode(cve));
236+
vuln.Description = "<p>"+sanitizer.Sanitize(HttpUtility.HtmlDecode(description))+"</p>"+ "<p>References: " +"<p>"+sanitizer.Sanitize(HttpUtility.HtmlDecode(refrences))+"</p>";
237+
vuln.ProofOfConcept = sanitizer.Sanitize(HttpUtility.HtmlDecode(pluginOutput));
238+
vuln.Impact = sanitizer.Sanitize(HttpUtility.HtmlDecode(impact));
236239
if (cvss != "")
237240
{
238241
vuln.CVSS3 = float.Parse(cvss,CultureInfo.InvariantCulture);
@@ -242,8 +245,8 @@ public void Parse(Guid? project, string user, string path)
242245
vuln.CVSS3 = 0;
243246
}
244247

245-
vuln.CVSSVector = cvssVector;
246-
vuln.Remediation = solution;
248+
vuln.CVSSVector = sanitizer.Sanitize(HttpUtility.HtmlDecode(cvssVector));
249+
vuln.Remediation = sanitizer.Sanitize(HttpUtility.HtmlDecode(solution));
247250
vuln.RemediationComplexity = RemediationComplexity.Low;
248251
vuln.RemediationPriority = RemediationPriority.Low;
249252
vuln.JiraCreated = false;

‎Cervantes.IFR/Parsers/Nmap/NmapParser.cs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.IO;
33
using System.Linq;
44
using System.Text;
5+
using System.Web;
56
using System.Xml;
67
using System.Xml.Linq;
78
using Cervantes.Contracts;
89
using Cervantes.CORE;
910
using Cervantes.CORE.Entities;
11+
using Ganss.Xss;
1012

1113

1214
namespace Cervantes.IFR.Parsers.Nmap;
@@ -34,7 +36,9 @@ public void Parse(Guid project, string user, string path)
3436
XElement nmap = XElement.Load(file);
3537

3638
var hosts = nmap.Descendants("host");
37-
39+
var sanitizer = new HtmlSanitizer();
40+
sanitizer.AllowedSchemes.Add("data");
41+
3842
foreach (var host in hosts)
3943
{
4044
var status = host.Element("status");
@@ -47,7 +51,7 @@ public void Parse(Guid project, string user, string path)
4751

4852
Target target = new Target
4953
{
50-
Name = address.Attribute("addr").Value,
54+
Name = sanitizer.Sanitize(HttpUtility.HtmlDecode(address.Attribute("addr").Value)),
5155
Description = "Imported from Nmap",
5256
Type = TargetType.IP,
5357
ProjectId = project,
@@ -131,10 +135,10 @@ public void Parse(Guid project, string user, string path)
131135
{
132136
UserId = user,
133137
TargetId = target.Id,
134-
Name = product + " (" + name +")",
135-
Description = info + Environment.NewLine + sb.ToString(),
138+
Name = sanitizer.Sanitize(HttpUtility.HtmlDecode(product)) + " (" + sanitizer.Sanitize(HttpUtility.HtmlDecode(name)) +")",
139+
Description = sanitizer.Sanitize(HttpUtility.HtmlDecode(info)) + Environment.NewLine + sanitizer.Sanitize(HttpUtility.HtmlDecode(sb.ToString())),
136140
Port = Int32.Parse(number),
137-
Version = version,
141+
Version =sanitizer.Sanitize(HttpUtility.HtmlDecode(version)),
138142
Note = "Imported from Nmap"
139143

140144

0 commit comments

Comments
 (0)