Skip to content

Commit

Permalink
semgrep: add rule to detect string interpolation in WithInfoMsg
Browse files Browse the repository at this point in the history
The event.WithInfoMsg function expects a set of key value tuples,
but it can easily be misunderstood to accept string interpolation
arguments. This check will error if any string interpolation verbs are
used in calls to event.WithInfoMsg
  • Loading branch information
johanbrandhorst committed Sep 23, 2024
1 parent 49a2118 commit 9c08e07
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .semgrep/event-with-info-msg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

rules:
- id: with-info-msg-string-interpolation
languages:
- go
severity: ERROR
message: Use of WithInfoMsg with string interpolation. WithInfoMsg expects kv
tuples.
# Source for Go string interpolation verbs:
# https://pkg.go.dev/fmt#hdr-Printing.
pattern: event.WithInfoMsg("=~/.*%(((\[\d+\])|[\d|\.|#|+|\-| |\*])*)?[s|v|q|d|T|t|b|c|o|O|x|X|U|e|E|f|F|g|G|p].*/",...)

0 comments on commit 9c08e07

Please sign in to comment.