Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ go run github.com/pb33f/libopenapi-validator/cmd/validate@latest --regexengine=e
- ignorecase
- multiline
- explicitcapture
- compiled
- compiled (legacy no-op, equivalent to none)
- singleline
- ignorepatternwhitespace
- righttoleft
Expand Down
2 changes: 1 addition & 1 deletion arazzo/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"strings"

"github.com/dlclark/regexp2"
"github.com/dlclark/regexp2/v2"
"github.com/pb33f/jsonpath/pkg/jsonpath"
jsonpathconfig "github.com/pb33f/jsonpath/pkg/jsonpath/config"
"github.com/pb33f/libopenapi/arazzo/expression"
Expand Down
2 changes: 1 addition & 1 deletion arazzo/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/dlclark/regexp2"
"github.com/dlclark/regexp2/v2"
"github.com/pb33f/jsonschema/v6"
)

Expand Down
45 changes: 45 additions & 0 deletions arazzo/regex_security_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package arazzo

import (
"errors"
"testing"

"github.com/dlclark/regexp2/v2"
)

func TestInputRegexZeroWidthRepeatLimit(t *testing.T) {
// 60,000 repetitions exceed the default 100,000-slot backtracking limit
// while keeping this regression safe to run against the old engine.
for _, pattern := range []string{`(?:^){60000}`, `(?:^){60000}?`} {
t.Run(pattern, func(t *testing.T) {
v := contractValidation(nil)
state := &inputRegexpState{v: v}
re, err := state.compile(pattern)
if err != nil {
t.Fatal(err)
}
if re.MatchString("") || !errors.Is(state.err, regexp2.ErrBacktrackingStackLimit) {
t.Fatalf("expected bounded match failure, got %v", state.err)
}
reportInputCompile(v, state, state.err, "/workflows/0/inputs")
var tool *Error
if !errors.As(v.err, &tool) || tool.Kind != ErrorOperational || !errors.Is(v.err, regexp2.ErrBacktrackingStackLimit) {
t.Fatalf("regex limit cause was lost: %v", v.err)
}
})
}
}

func TestInputRegexEmptyRepeat(t *testing.T) {
state := &inputRegexpState{v: contractValidation(nil)}
re, err := state.compile(`(?:){60000}`)
if err != nil {
t.Fatal(err)
}
if !re.MatchString("") || state.err != nil {
t.Fatalf("literal empty repetition must remain valid: %v", state.err)
}
}
2 changes: 1 addition & 1 deletion arazzo/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type nonDollarPattern struct{}

func (nonDollarPattern) String() string { return `^(?!\$).+$` }
func (nonDollarPattern) MatchString(s string) bool {
return s != "" && s[0] != '$' && !strings.ContainsAny(s, "\r\n")
return s != "" && s[0] != '$' && !strings.ContainsAny(s, "\r\n\u2028\u2029")
}

func compileSchemaPattern(pattern string) (jsonschema.Regexp, error) {
Expand Down
2 changes: 1 addition & 1 deletion arazzo/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"sync/atomic"
"testing"

"github.com/dlclark/regexp2"
"github.com/dlclark/regexp2/v2"
"github.com/pb33f/go-yaml"
)

Expand Down
13 changes: 8 additions & 5 deletions cmd/validate/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package main

import (
Expand All @@ -7,7 +10,7 @@ import (
"log/slog"
"os"

"github.com/dlclark/regexp2"
"github.com/dlclark/regexp2/v2"
"github.com/goccy/go-yaml"
"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi"
Expand All @@ -28,7 +31,7 @@ func (re *customRegexp) String() string {
}

type regexEngine struct {
runtimeOption regexp2.RegexOptions
runtimeOption regexp2.CompileOption
}

func (e *regexEngine) run(s string) (jsonschema.Regexp, error) {
Expand All @@ -39,16 +42,16 @@ func (e *regexEngine) run(s string) (jsonschema.Regexp, error) {
return (*customRegexp)(re), nil
}

var regexParsingOptionsMap = map[string]regexp2.RegexOptions{
var regexParsingOptionsMap = map[string]regexp2.CompileOption{
"none": regexp2.None,
"ignorecase": regexp2.IgnoreCase,
"multiline": regexp2.Multiline,
"explicitcapture": regexp2.ExplicitCapture,
"compiled": regexp2.Compiled,
"compiled": regexp2.None, // Legacy no-op; regexp2/v2 removed the unused flag.
"singleline": regexp2.Singleline,
"ignorepatternwhitespace": regexp2.IgnorePatternWhitespace,
"righttoleft": regexp2.RightToLeft,
"debug": regexp2.Debug,
"debug": regexp2.OptionDebug(),
"ecmascript": regexp2.ECMAScript,
"re2": regexp2.RE2,
"unicode": regexp2.Unicode,
Expand Down
42 changes: 42 additions & 0 deletions cmd/validate/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package main

import "testing"

func TestRegexEngineOptions(t *testing.T) {
for name, option := range regexParsingOptionsMap {
t.Run(name, func(t *testing.T) {
engine := &regexEngine{runtimeOption: option}
re, err := engine.run("abc")
if err != nil {
t.Fatal(err)
}
if re.String() != "abc" || !re.MatchString("abc") || re.MatchString("xyz") {
t.Fatal("regex option changed matching behavior")
}
if _, err := engine.run("["); err == nil {
t.Fatal("invalid regex compiled")
}
})
}
}

func TestRegexEngineZeroWidthRepeatLimit(t *testing.T) {
engine := &regexEngine{runtimeOption: regexParsingOptionsMap["ecmascript"]}
re, err := engine.run(`(?:^){60000}`)
if err != nil {
t.Fatal(err)
}
if re.MatchString("") {
t.Fatal("excessive zero-width repetition must fail closed")
}
empty, err := engine.run(`(?:){60000}`)
if err != nil {
t.Fatal(err)
}
if !empty.MatchString("") {
t.Fatal("literal empty repetition must remain valid")
}
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ go 1.26.0

require (
github.com/basgys/goxml2json v1.1.1-0.20231018121955-e66ee54ceaad
github.com/dlclark/regexp2 v1.12.0
github.com/dlclark/regexp2/v2 v2.12.0
github.com/go-openapi/jsonpointer v1.0.2
github.com/goccy/go-yaml v1.19.2
github.com/pb33f/go-yaml v0.1.1
github.com/pb33f/jsonpath v0.8.4
github.com/pb33f/jsonpath v0.8.5
github.com/pb33f/jsonschema/v6 v6.0.3
github.com/pb33f/libopenapi v0.41.6
github.com/pb33f/libopenapi v0.41.8
github.com/pb33f/testify v0.1.1
golang.org/x/text v0.43.0
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.2 // indirect
github.com/buger/jsonparser v1.6.1 // indirect
github.com/pb33f/ordered-map/v2 v2.3.2 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/net v0.62.0 // indirect
golang.org/x/sync v0.24.0 // indirect
)
22 changes: 12 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ github.com/basgys/goxml2json v1.1.1-0.20231018121955-e66ee54ceaad h1:3swAvbzgfaI
github.com/basgys/goxml2json v1.1.1-0.20231018121955-e66ee54ceaad/go.mod h1:9+nBLYNWkvPcq9ep0owWUsPTLgL9ZXTsZWcCSVGGLJ0=
github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow=
github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q=
github.com/buger/jsonparser v1.1.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
github.com/buger/jsonparser v1.1.2/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/buger/jsonparser v1.6.1 h1:I0phFv0PlbLHnM7TZAVjZ2MJ2/eWRTDyuO7GLR98IEs=
github.com/buger/jsonparser v1.6.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8=
github.com/dlclark/regexp2 v1.12.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dlclark/regexp2/v2 v2.12.0 h1:GsCgDZZeHluUDHASr2yqQonZk4Tma5LFmLH9CSsFFEE=
github.com/dlclark/regexp2/v2 v2.12.0/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
github.com/go-openapi/jsonpointer v1.0.2 h1:NbW7xT2b+l7x+JefiPGDsZWsrLk1ogrz4AHK1TTzMt8=
github.com/go-openapi/jsonpointer v1.0.2/go.mod h1:N0rI4MbNKD7xAFTiHtB+5Nhrg2j/wwYg7m7Fmb4/jk8=
github.com/go-openapi/testify/v2 v2.8.0 h1:19QDx5b57p8KjO2E4sgs/woL4Akp+FGLRlVm2xn0Rho=
Expand All @@ -19,12 +21,12 @@ github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/pb33f/go-yaml v0.1.1 h1:yWGmhVdwzionRnSc/hEJwcfq6PaZL2QdYzyReXBbX7Q=
github.com/pb33f/go-yaml v0.1.1/go.mod h1:QvWdkHP5VjFYAeHMQUkaPQqREaQnBNOXmWzAjNrnSdo=
github.com/pb33f/jsonpath v0.8.4 h1:Yx7fxsKl8scgERL22WhKDs2c6gYNNUonPSWEG8Y194s=
github.com/pb33f/jsonpath v0.8.4/go.mod h1:eO6mgdhw5RgzCxm/bXTi75VUs0/cCYJzdGjMCCUEI6M=
github.com/pb33f/jsonpath v0.8.5 h1:wsbwJbz6MPUTy5fAtiIlOyQb3oblaa5M7qjtdz6orPw=
github.com/pb33f/jsonpath v0.8.5/go.mod h1:eO6mgdhw5RgzCxm/bXTi75VUs0/cCYJzdGjMCCUEI6M=
github.com/pb33f/jsonschema/v6 v6.0.3 h1:TMIkE1xCmnF8Cy+anIBs+r4ASfGtwzfFxYsrrIn0wSU=
github.com/pb33f/jsonschema/v6 v6.0.3/go.mod h1:cYPShw+w1Jrs0YgpE2rk1FLdIAsKfWcotv/54G6ddFo=
github.com/pb33f/libopenapi v0.41.6 h1:W1X/5rOaAk3/Mjwrt+DHaiJO6buhruKWrbQ+pumONkA=
github.com/pb33f/libopenapi v0.41.6/go.mod h1:mUldESjO6ownR1TCcywvoYp7e4v/bCdQyiiIqsgWne0=
github.com/pb33f/libopenapi v0.41.8 h1:SCqrRbHNodEJjyLRFhvUkLyjQ1H+1W0fxhR+oCslRis=
github.com/pb33f/libopenapi v0.41.8/go.mod h1:IlfeXtmcY38KEnGJ4OMWFA8I62BCNamuQa8omLnk6R0=
github.com/pb33f/ordered-map/v2 v2.3.2 h1:wDyaZ2Pv9QLh64X4utCeD5Zoi9nIv2aW3lwv172O5PQ=
github.com/pb33f/ordered-map/v2 v2.3.2/go.mod h1:1OhFrXu3OYw3kM+FXF+Ug3ugmmZ9LE8z0JfQMLvtV0w=
github.com/pb33f/testify v0.1.1 h1:mnHe7uxKt8dyNYEGUspow72VjD264DB5rOJq4bz5tJw=
Expand All @@ -47,8 +49,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
2 changes: 1 addition & 1 deletion validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"testing"
"unicode"

"github.com/dlclark/regexp2"
"github.com/dlclark/regexp2/v2"
"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi"
"github.com/pb33f/testify/assert"
Expand Down
Loading