Notes returned as valid json instead of inspected string over RPC#21292
Notes returned as valid json instead of inspected string over RPC#21292sjanusz-r7 wants to merge 1 commit intorapid7:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the db.notes RPC endpoint output so note data is returned as structured content (rather than an inspected string), aligning the RPC response with how notes are stored/used elsewhere in the framework.
Changes:
- Return
Mdm::Note#datadirectly fromrpc_notesinstead ofn.data.inspect.
| note[:type ] = n.ntype.to_s | ||
| note[:data] = n.data.inspect | ||
| note[:data] = n.data | ||
| ret[:notes] << note |
There was a problem hiding this comment.
rpc_notes now returns n.data directly, which (1) does not implement the requested backward compatibility for legacy notes where data is a plain String (issue asks to convert those to a JSON-like object such as { "data": "..." }), and (2) can return non-JSON/MessagePack-friendly values (e.g., nested Symbols, Times, custom objects) that previously were safely stringified via inspect. Consider normalizing the outgoing value to JSON-safe primitives (deep-stringify keys and coerce unknown values), and wrapping non-Hash data in a predictable structure; also update the YARD docs above this method which still state 'data' [String].
fe2ed7a to
6a6dffc
Compare
6a6dffc to
0446c0d
Compare
| note[:service] = n.service.name || n.service.port if n.service | ||
| note[:type ] = n.ntype.to_s | ||
| note[:data] = n.data.inspect | ||
| note[:data] = n.data |
There was a problem hiding this comment.
This change alters the db.notes RPC response shape (data is no longer always a String). There are existing RPC v10 specs (e.g., for console/core/session), but none covering RPC_Db#rpc_notes; adding a spec that exercises rpc_notes with (1) Hash note data, (2) legacy String note data, and (3) nil/edge cases would help prevent regressions and validate the intended serialization behavior.
There was a problem hiding this comment.
I second the idea of further rspec tests
Closes #21249
Tested in Pro under
workspaces/1/notesBefore
Data is inspected, returned as a single string
In Pro, the data is also rendered correctly:

After
Data is parsed correctly as a hash
Pro also renders the hash correctly, with no changes to functionality:

In Pro, the code should handle this automatically where necessary as it calls off to:
which handles the
Hashscenario.JSON RPC
This also works out of the box with the JSON RPC layer:
{ "time": 1776160491, "host": "127.0.0.1", "service": "", "type": "host.comments", "data": { "host_data": "hello world, this is a comment" } }, { "time": 1776072168, "host": "", "service": "", "type": "evasion.fileformat.syscall_inject.localpath", "data": { "full_path": "/Users/sjanusz/.msf4/local/met.exe" } },Verification
List the steps needed to make sure this thing works
msfconsoleload msgrpcrpc.call("db.notes", {})works and returns the expected notes data in correct format