Skip to content

Commit

Permalink
feat: stricter validation for expected comments (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfabianski authored Feb 22, 2024
1 parent f6c002f commit 1f04488
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/scanner/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ast
import (
"context"
"fmt"
"regexp"
"strings"

"github.com/rs/zerolog/log"
Expand All @@ -15,6 +16,8 @@ import (
"github.com/bearer/bearer/internal/scanner/ast/tree"
)

var ExpectedComment = regexp.MustCompile(`\A[^\w]*bearer:expected\s[\w,]+\z`)

func Parse(
ctx context.Context,
language language.Language,
Expand Down Expand Up @@ -116,7 +119,7 @@ func addExpectedRules(
nextExpectedRules := expectedRules

nodeContent := builder.ContentFor(node)
if strings.Contains(nodeContent, "bearer:expected") {
if ExpectedComment.Match([]byte(nodeContent)) {
rawRuleIDs := strings.Split(nodeContent, "bearer:expected")[1]

for _, ruleID := range strings.Split(rawRuleIDs, ",") {
Expand Down

0 comments on commit 1f04488

Please sign in to comment.