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

openapi3filter: ensure key matches param name before decoding in (*urlValuesDecoder) DecodeObject(..) #947

Merged
merged 1 commit into from
May 11, 2024
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
4 changes: 4 additions & 0 deletions openapi3filter/req_resp_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ func (d *urlValuesDecoder) DecodeObject(param string, sm *openapi3.Serialization
propsFn = func(params url.Values) (map[string]string, error) {
props := make(map[string]string)
for key, values := range params {
if !regexp.MustCompile(fmt.Sprintf(`^%s\[`, regexp.QuoteMeta(param))).MatchString(key) {
continue
}

matches := regexp.MustCompile(`\[(.*?)\]`).FindAllStringSubmatch(key, -1)
switch l := len(matches); {
case l == 0:
Expand Down
11 changes: 11 additions & 0 deletions openapi3filter/req_resp_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,17 @@ func TestDecodeParameter(t *testing.T) {
query: "anotherparam=bar",
want: map[string]interface{}(nil),
},
{
name: "deepObject explode nested object - extraneous deep object param ignored",
param: &openapi3.Parameter{
Name: "param", In: "query", Style: "deepObject", Explode: explode,
Schema: objectOf(
"obj", objectOf("nestedObjOne", stringSchema, "nestedObjTwo", stringSchema),
),
},
query: "anotherparam[obj][nestedObjOne]=one&anotherparam[obj][nestedObjTwo]=two",
want: map[string]interface{}(nil),
},
{
name: "deepObject explode nested object - bad array item type",
param: &openapi3.Parameter{
Expand Down
Loading