Skip to content

EventLogService: XPath injection risk in query filter construction #224

@Christophe-Rogiers

Description

@Christophe-Rogiers

Bug Description

SourceName is interpolated directly into an XPath query string without escaping. Currently the source is hardcoded to "Servy" so the immediate risk is low, but the pattern is fragile and would allow XPath injection if the source were ever configurable or contained a single quote.

Location

File: src/Servy.Core/Services/EventLogService.cs
Lines: 47, 54, 59

Code

systemFilters.Add($"Provider[@Name='{SourceName}']");
systemFilters.Add($"TimeCreated[@SystemTime >= '{startUtc:o}']");
systemFilters.Add($"TimeCreated[@SystemTime <= '{endUtc:o}']");

Suggested Fix

Escape single quotes in interpolated values, or use SecurityElement.Escape():

var escapedName = SourceName.Replace("'", "&apos;");
systemFilters.Add($"Provider[@Name='{escapedName}']");

Severity

Warning

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions