Skip to content

Commit 50c7b9e

Browse files
authored
Merge pull request #1838 from l3montree-dev/add-saveguards-to-sarif-upload
Added size limit check for sarif upload and implemented nil pointer checks for regions
2 parents f08580b + 9b9b6fb commit 50c7b9e

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

controllers/scan_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"fmt"
2121
"log/slog"
22+
"net/http"
2223
"time"
2324

2425
cdx "github.com/CycloneDX/cyclonedx-go"
@@ -404,6 +405,9 @@ func (s *ScanController) FirstPartyVulnScan(ctx shared.Context) error {
404405

405406
var sarifScan sarif.SarifSchema210Json
406407

408+
var maxSize int64 = 16 * 1024 * 1024 //Max Upload Size 16mb
409+
410+
ctx.Request().Body = http.MaxBytesReader(ctx.Response(), ctx.Request().Body, maxSize)
407411
defer ctx.Request().Body.Close()
408412

409413
if err := ctx.Bind(&sarifScan); err != nil {

services/scan_service.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,29 @@ func (s *scanService) HandleFirstPartyVulnResult(ctx context.Context, org models
239239
loc := result.Locations[0]
240240
firstPartyVulnerability.URI = utils.OrDefault(loc.PhysicalLocation.ArtifactLocation.URI, "")
241241

242-
snippetContent := dtos.SnippetContent{
243-
StartLine: utils.OrDefault(loc.PhysicalLocation.Region.StartLine, 0),
244-
EndLine: utils.OrDefault(loc.PhysicalLocation.Region.EndLine, 0),
245-
StartColumn: utils.OrDefault(loc.PhysicalLocation.Region.StartColumn, 0),
246-
EndColumn: utils.OrDefault(loc.PhysicalLocation.Region.EndColumn, 0),
247-
Snippet: utils.OrDefault(loc.PhysicalLocation.Region.Snippet.Text, ""),
242+
var snippetContent dtos.SnippetContent
243+
244+
if loc.PhysicalLocation.Region == nil {
245+
snippetContent = dtos.SnippetContent{
246+
StartLine: 0,
247+
EndLine: 0,
248+
StartColumn: 0,
249+
EndColumn: 0,
250+
Snippet: "",
251+
}
252+
} else {
253+
var checkedSnippet = ""
254+
if loc.PhysicalLocation.Region.Snippet != nil {
255+
checkedSnippet = utils.OrDefault(loc.PhysicalLocation.Region.Snippet.Text, "")
256+
}
257+
258+
snippetContent = dtos.SnippetContent{
259+
StartLine: utils.OrDefault(loc.PhysicalLocation.Region.StartLine, 0),
260+
EndLine: utils.OrDefault(loc.PhysicalLocation.Region.EndLine, 0),
261+
StartColumn: utils.OrDefault(loc.PhysicalLocation.Region.StartColumn, 0),
262+
EndColumn: utils.OrDefault(loc.PhysicalLocation.Region.EndColumn, 0),
263+
Snippet: checkedSnippet,
264+
}
248265
}
249266

250267
hash = firstPartyVulnerability.CalculateHash()

0 commit comments

Comments
 (0)