Skip to content

Commit ca737df

Browse files
fix: potentially unsafe quoting (#913)
CodeQL always complained about this code and Copilot had a suggestion which solves it even though it wasn't really a problem in practice. Signed-off-by: Chris Gianelloni <[email protected]> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 1495848 commit ca737df

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

cbor/value.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,15 @@ func generateAstJsonMap[T map[any]any | Map](v T) ([]byte, error) {
231231
if err != nil {
232232
return nil, err
233233
}
234-
// NOTE: Github CodeQL hates this due to "potentially unsafe quoting", but it
235-
// won't happen in practice since both values injected are auto-generated
236-
tmpJson := fmt.Sprintf(
237-
`{"k":%s,"v":%s}`,
238-
keyAstJson,
239-
valAstJson,
240-
)
241-
tmpItems = append(tmpItems, tmpJson)
234+
tmpJsonMap := map[string]json.RawMessage{
235+
"k": keyAstJson,
236+
"v": valAstJson,
237+
}
238+
tmpJson, err := json.Marshal(tmpJsonMap)
239+
if err != nil {
240+
return nil, err
241+
}
242+
tmpItems = append(tmpItems, string(tmpJson))
242243
}
243244
// We naively sort the rendered map items to give consistent ordering
244245
sort.Strings(tmpItems)

0 commit comments

Comments
 (0)