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

Validate URI query string encoding #183

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Changes from 3 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
24 changes: 20 additions & 4 deletions cel/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ func (l library) CompileOptions() []cel.EnvOption {
if !ok {
return types.Bool(false)
}
uri, err := url.Parse(s)
return types.Bool(err == nil && uri.IsAbs())
return types.Bool(l.validateURI(s, true))
}),
),
),
Expand All @@ -247,8 +246,7 @@ func (l library) CompileOptions() []cel.EnvOption {
if !ok {
return types.Bool(false)
}
_, err := url.Parse(s)
return types.Bool(err == nil)
return types.Bool(l.validateURI(s, false))
}),
),
),
Expand Down Expand Up @@ -479,6 +477,24 @@ func (l library) validateIPPrefix(p string, ver int64, strict bool) bool {
}
}

func (l library) validateURI(val string, checkAbs bool) bool {
uri, err := url.Parse(val)
if err != nil {
return false
}
if checkAbs {
ok := uri.IsAbs()
if !ok {
smaye81 marked this conversation as resolved.
Show resolved Hide resolved
return false
}
}
if _, err := url.ParseQuery(uri.RawQuery); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here real quick why this is necessary for future contributors who might wonder why it's necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, done. Let me know if it needs more detail.

return false
}

return true
smaye81 marked this conversation as resolved.
Show resolved Hide resolved
}

func (l library) isHostAndPort(val string, portRequired bool) bool {
if len(val) == 0 {
return false
Expand Down