Sanitize user input in AnalysisTriggerService and ThermalReferenceMetadataService log entries - #372
Merged
Christdej merged 1 commit intoMay 22, 2026
Conversation
Christdej
force-pushed
the
fix/codeql-log-forging-analysis-and-thermal
branch
3 times, most recently
from
May 22, 2026 10:11
5168595 to
ab453b3
Compare
Eddasol
approved these changes
May 22, 2026
Christdej
force-pushed
the
fix/codeql-log-forging-analysis-and-thermal
branch
from
May 22, 2026 10:18
ab453b3 to
3a3b6e3
Compare
…adataService log entries
Christdej
force-pushed
the
fix/codeql-log-forging-analysis-and-thermal
branch
from
May 22, 2026 10:23
3a3b6e3 to
7104baf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 13 open CodeQL
cs/log-forging(CWE-117) code-scanning alerts by re-applying the existingSanitize.SanitizeUserInputhelper at the public service entry points, mirroring the established pattern from commit ac46c14 (fix(api): sanitize user input in PlantDataService log entries).Why this is needed
The controllers and MQTT handlers already sanitize incoming user-controlled values, but CodeQL's
cs/log-forgingtaint analysis does not follow the customSanitize.SanitizeUserInputhelper across method/MQTT/DB boundaries. Re-applying the sanitizer at the service entry point keeps the data-flow local and recognized by the analysis, eliminating the alerts without changing observable behavior.Changes
api/Services/AnalysisTriggerService.cs(10 alerts)OnInspectionRecordCreated: sanitizeinspectionRecord.InspectionId,createdEvent.AnalysisGroup.AnalysisGroupId,createdEvent.AnalysisGroup.AnalysisGroupAnalysesitems, andcreatedEvent.RequiredAnalysisitems at the top of the method (right after the null check oninspectionRecord).RerunAnalysis: sanitizeanalysis.Nameand eachrecord.InspectionIdafter loading from the DB.GetOrCreateAnalysisGroup: re-sanitizeexisting.GroupIdwhen an existing group is loaded from the DB, since CodeQL still treats stored strings as tainted across the round-trip.api/Services/ThermalReferenceMetadataService.cs(3 alerts)CreateThermalReferenceMetadataandUpdateThermalReferenceMetadata: sanitizeinput.InstallationCode,input.TagId,input.InspectionDescriptionat the top of each method (so the sanitized values are also what get persisted to the DB — matching thePlantDataService.CreatePlantDatapattern).using api.Utilities;.False positives?
None of the 13 alerts are false positives in CodeQL's threat model — all tainted values originate from
[FromBody]HTTP requests or MQTT messages. The fixes resolve them properly rather than dismissing.Verification
dotnet build api/api.csprojsucceeds with 0 warnings / 0 errors.\r/\nfrom the listed user-controlled strings (already done at the controller layer for most fields; this PR makes it visible to CodeQL and also defends in depth).Code-scanning alerts addressed
ThermalReferenceMetadataService.cs:AnalysisTriggerService.cs: