-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Make sure to escape user strings #2433
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,6 @@ func RegisterHandlersWithOptions(router EchoRouter, si ServerInterface, options | |||||
| Handler: si, | ||||||
| } | ||||||
| {{end}} | ||||||
| {{range .}}router.{{.Method}}(options.BaseURL + "{{.Path | swaggerUriToEchoUri}}", wrapper.{{.HandlerName}}, options.OperationMiddlewares["{{.MiddlewareKey}}"]...) | ||||||
| {{range .}}router.{{.Method}}(options.BaseURL + {{.Path | swaggerUriToEchoUri | toGoString}}, wrapper.{{.HandlerName}}, options.OperationMiddlewares["{{.MiddlewareKey}}"]...) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This PR fixes injection for
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: pkg/codegen/templates/echo/echo-register.tmpl
Line: 50
Comment:
**Unescaped `MiddlewareKey` in map literal**
This PR fixes injection for `.Path` but the `{{.MiddlewareKey}}` value in `options.OperationMiddlewares["{{.MiddlewareKey}}"]` is still interpolated without escaping. `MiddlewareKey()` returns the raw `SpecOperationId` from the spec verbatim (see `operations.go:385`), so an operation ID containing a double-quote — e.g. `get"resource"` — would produce malformed Go output. The same issue exists in `echo/v5/echo-register.tmpl`. Replacing with `{{.MiddlewareKey | toGoString}}` would be consistent with the rest of this fix.
```suggestion
{{range .}}router.{{.Method}}(options.BaseURL + {{.Path | swaggerUriToEchoUri | toGoString}}, wrapper.{{.HandlerName}}, options.OperationMiddlewares[{{.MiddlewareKey | toGoString}}]...)
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| {{end}} | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,6 @@ func RegisterHandlersWithOptions(router EchoRouter, si ServerInterface, options | |||||
| Handler: si, | ||||||
| } | ||||||
| {{end}} | ||||||
| {{range .}}router.{{.Method}}(options.BaseURL + "{{.Path | swaggerUriToEchoUri}}", wrapper.{{.HandlerName}}, options.OperationMiddlewares["{{.MiddlewareKey}}"]...) | ||||||
| {{range .}}router.{{.Method}}(options.BaseURL + {{.Path | swaggerUriToEchoUri | toGoString}}, wrapper.{{.HandlerName}}, options.OperationMiddlewares["{{.MiddlewareKey}}"]...) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: pkg/codegen/templates/echo/v5/echo-register.tmpl
Line: 50
Comment:
Same unescaped `MiddlewareKey` issue as in `echo/echo-register.tmpl` — the raw spec `OperationId` is interpolated directly into a map-key string literal without going through `toGoString`.
```suggestion
{{range .}}router.{{.Method}}(options.BaseURL + {{.Path | swaggerUriToEchoUri | toGoString}}, wrapper.{{.HandlerName}}, options.OperationMiddlewares[{{.MiddlewareKey | toGoString}}]...)
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| {{end}} | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the repo's contribution guidelines, bug fixes should include a regression test in
internal/test/. Neither a new fixture spec (with a path or string enum value containing"or\) nor a corresponding*.gen.gowas added. Without this, a future template change could silently re-introduce the injection bug and CI would not catch it.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!