Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC : regex/s are vulnerable for validation #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
76 changes: 76 additions & 0 deletions examples/fuzz/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"context"
"fmt"
"net/mail"

"github.com/pkg-id/goval"
"github.com/pkg-id/goval/govalregex"
)

func main() {
test_email()
test_numeric()
test_rgb()
}

func test_rgb() {

Check failure on line 18 in examples/fuzz/main.go

View workflow job for this annotation

GitHub Actions / Performance regression check (1.19.x)

internal compiler error: 'test_rgb': Value live at entry. It shouldn't be. func test_rgb, node goval..dict1, value v219
fmt.Println("\n\ntest_numeric()")

rgbValues := []string{
"rgb(50%, 25%, 75%))", // invalid double ))
"rgb(100%, 101%, 50%)", // should invalid value : 101%
"rgb(50%, 25%, 75%)", // valid
}
validator := goval.String().Required().Min(2).Match(govalregex.RGB)
ctx := context.Background()
for _, v := range rgbValues {
validateErr := validator.Validate(ctx, v)
if validateErr == nil {
fmt.Println("govalregex RGB is valid : ", v)
} else {
fmt.Println("govalregex RGB isn't valid : ", v)
}
}
}

func test_numeric() {
fmt.Println("\n\ntest_numeric()")

zero := "0" // result : valid
minZero := "-0" // result : valid
validator := goval.String().Required().Match(govalregex.Numeric)
ctx := context.Background()
for _, v := range []string{zero, minZero} {
validateErr := validator.Validate(ctx, v)
if validateErr == nil {
fmt.Println("govalregex numeric, v is valid : ", v)
} else {
fmt.Println("govalregex numeric, v isn't valid : ", v)
}
}
}

func test_email() {

Check failure on line 55 in examples/fuzz/main.go

View workflow job for this annotation

GitHub Actions / Performance regression check (1.18.x)

internal compiler error: 'test_email': Value live at entry. It shouldn't be. func test_email, node goval..dict1, value v263

Check failure on line 55 in examples/fuzz/main.go

View workflow job for this annotation

GitHub Actions / build (1.18.x)

internal compiler error: 'test_email': Value live at entry. It shouldn't be. func test_email, node goval..dict1, value v284

Check failure on line 55 in examples/fuzz/main.go

View workflow job for this annotation

GitHub Actions / build (1.19.x)

internal compiler error: 'test_email': Value live at entry. It shouldn't be. func test_email, node goval..dict1, value v284
fmt.Println("test_email()")

email := "user@example.com." // invalid email
validator := goval.String().Required().Min(2).Match(govalregex.Email)
ctx := context.Background()
validateErr := validator.Validate(ctx, email)
if validateErr == nil {
fmt.Println("govalregex email is valid : ", email)
} else {
fmt.Println("govalregex email isn't valid : ", email)
}

// easy way to validate email
// or another way is use validate/v10 package
e, parseErr := mail.ParseAddress(email)
if parseErr == nil {
fmt.Println("net/mail email is valid : ", e)
} else {
fmt.Println("net/mail email isn't valid : ", e)
}
}
Loading