Skip to content

Conversation

@davidleitw
Copy link
Contributor

Handle nil RawMessage and explicit JSON "null" in unmarshalParams to prevent server crashes. When JSON-RPC requests are sent without parameters or with null parameters, ensure orZero receives a valid struct instead of nil.

Fixes #186 - DoS vulnerability where missing params caused server panic

Changes:

  • Add nullJSON constant for efficient null comparison
  • Handle nil RawMessage by creating empty parameter struct
  • Handle explicit "null" JSON using bytes.Equal
  • Integrate with upstream methodFlags system for proper param validation
  • Add comprehensive test coverage for nil parameter scenarios

Behavior:

  • Methods with missingParamsOK flag: gracefully handle nil/null params
  • Methods without flag: return proper error instead of crashing
  • Maintains backward compatibility with existing error handling

Security Impact:

  • Eliminates DoS attack vector via malformed JSON-RPC requests
  • Server continues running instead of crashing on bad input

@davidleitw
Copy link
Contributor Author

davidleitw commented Jul 31, 2025

@jba Thanks for the review! I've actually updated this PR based on the discussion in #186 - it now only contains test improvements and no longer includes the fix logic (since #210 already resolved the core issue). The code you're commenting on has been removed.

The PR now just adds complementary unit test coverage for the methodFlags system.

findleyr
findleyr previously approved these changes Aug 4, 2025
Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

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

Thanks!

@findleyr
Copy link
Contributor

findleyr commented Aug 4, 2025

It looks like this PR does not format cleanly. Could you please run go fmt?

@davidleitw
Copy link
Contributor Author

ok~ let me fix it

Complements the methodFlags system from modelcontextprotocol#210 with additional unit tests:
- Tests nil RawMessage and explicit JSON null handling in unmarshalParams
- Tests edge cases with different JSON types (empty string, array, number, boolean)
- Validates proper error handling for required vs optional params with methodFlags
- Provides focused unit test coverage alongside existing conformance tests

The tests verify that the panic vulnerability from modelcontextprotocol#186 is properly handled
by the upstream methodFlags implementation.
@findleyr findleyr requested review from findleyr and jba and removed request for jba August 5, 2025 16:23
@jba jba merged commit be0bd77 into modelcontextprotocol:main Aug 5, 2025
3 checks passed
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.

Able to crash a server from improper handling of nil params

3 participants