Skip to content

Commit

Permalink
fix(parser): validate cookie parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Mar 1, 2023
1 parent 3a0d414 commit 3eb6d6f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"openapi": "3.0.3",
"info": {
"title": "title",
"version": "v0.1.0"
},
"paths": {
"/foo": {
"get": {
"parameters": [
{
"name": "",
"in": "cookie",
"style": "form",
"explode": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "User info"
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions openapi/parser/parse_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"golang.org/x/net/http/httpguts"

"github.com/ogen-go/ogen"
"github.com/ogen-go/ogen/internal/httpcookie"
"github.com/ogen-go/ogen/internal/jsonpointer"
"github.com/ogen-go/ogen/internal/location"
"github.com/ogen-go/ogen/jsonschema"
Expand Down Expand Up @@ -110,6 +111,11 @@ func (p *parser) validateParameter(
err := errors.Errorf("invalid header name %q", name)
return p.wrapField("name", file, locator, err)
}
case openapi.LocationCookie:
if !httpcookie.IsCookieNameValid(name) {
err := errors.Errorf("invalid cookie name %q", name)
return p.wrapField("name", file, locator, err)
}
}
return nil
}
Expand Down

0 comments on commit 3eb6d6f

Please sign in to comment.