Skip to content

fix(middleware): nil-guard param.Schema in UntypedRequestBinder map path#488

Merged
fredbi merged 2 commits into
masterfrom
copilot/fix-issue-487-fuzz-test
Jun 19, 2026
Merged

fix(middleware): nil-guard param.Schema in UntypedRequestBinder map path#488
fredbi merged 2 commits into
masterfrom
copilot/fix-issue-487-fuzz-test

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

UntypedRequestBinder.Bind panics with a nil pointer dereference when binding into map[string]any and a parameter has Schema == nil (normal for non-body params like query/path/header with malformed or edge-case type definitions).

The panic path: binder.Type() returns nil → code falls through to param.Schema.Type.Contains(typeArray) → nil dereference.

Changes

  • middleware/request.go: Guard param.Schema before dereferencing:

    if param.Schema != nil && param.Schema.Type.Contains(typeArray) {

    When schema is nil, falls through to map[string]any default — correct for non-array params.

  • middleware/request_nilschema_test.go: Regression unit tests for nil-schema and array-schema map-binding paths, plus a fuzz test (FuzzUntypedRequestBinder) exercising varied parameter shapes through the isMap code path.

…er (#487)

Add nil check for param.Schema before dereferencing it in the isMap
binding path (request.go:76). When binder.Type() returns nil and the
parameter has no Schema (common for non-body params with malformed
definitions), the code previously panicked with a nil pointer
dereference.

Add regression unit tests and a fuzz test exercising the map-binding
path with varied parameter shapes.

Fixes #487

Signed-off-by: Copilot <copilot@github.com>
Copilot AI changed the title fix(middleware): guard against nil param.Schema in UntypedRequestBinder (#487) fix(middleware): nil-guard param.Schema in UntypedRequestBinder map path Jun 19, 2026
Copilot AI requested a review from fredbi June 19, 2026 05:39
@fredbi fredbi marked this pull request as ready for review June 19, 2026 05:50
@fredbi

fredbi commented Jun 19, 2026

Copy link
Copy Markdown
Member

Linter is complaining:

  1. Genuine offender
    ^
    Error: /home/runner/work/runtime/runtime/middleware/request_nilschema_test.go:82:14: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)

  2. linter noise goconst

please relax goconst settings in .golangci.yml
By limiting issues on identifiers of length > 8

@fredbi fredbi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Linter is complaining:

Genuine offender
^
Error: /home/runner/work/runtime/runtime/middleware/request_nilschema_test.go:82:14: unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)

linter noise goconst

please relax goconst settings in .golangci.yml
By limiting issues on identifiers of length > 8

Rename unused `t` parameter to `_` in FuzzUntypedRequestBinder.
Relax goconst min-len from 2 to 9 to suppress noise on short identifiers.

Signed-off-by: Copilot <copilot@github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Linter is complaining:

Genuine offender...

Fixed in b7db1f4: renamed unused t to _ in the fuzz function, and relaxed goconst.min-len from 2 to 9 in .golangci.yml.

Copilot AI requested a review from fredbi June 19, 2026 06:02
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.36%. Comparing base (1733ca7) to head (b7db1f4).
⚠️ Report is 7 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #488   +/-   ##
=======================================
  Coverage   83.36%   83.36%           
=======================================
  Files          64       64           
  Lines        4520     4520           
=======================================
  Hits         3768     3768           
- Misses        582      583    +1     
+ Partials      170      169    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@fredbi fredbi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread middleware/request.go
tpe := binder.Type()
if tpe == nil {
if param.Schema.Type.Contains(typeArray) {
if param.Schema != nil && param.Schema.Type.Contains(typeArray) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok

data := make(map[string]any)
_ = binder.Bind(req, nil, runtime.JSONConsumer(), &data) // must not panic
})
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok

@fredbi fredbi merged commit d3cd4f6 into master Jun 19, 2026
33 checks passed
@fredbi fredbi deleted the copilot/fix-issue-487-fuzz-test branch June 19, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants