-
Notifications
You must be signed in to change notification settings - Fork 15
fix: validate username and truncate worker name at authorize time #197
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
base: main
Are you sure you want to change the base?
fix: validate username and truncate worker name at authorize time #197
Conversation
67bf1cf to
190ec4c
Compare
|
Rebased onto #162 Pr ot that branch here: |
190ec4c to
30d4718
Compare
miner-apps/translator/src/lib/sv1/sv1_server/downstream_message_handler.rs
Outdated
Show resolved
Hide resolved
| MAX_USER_IDENTITY_LENGTH, | ||
| username.len() | ||
| ); | ||
| return false; |
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.
Is there a more specific error type we should use here?
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.
The return type is defined upstream in stratum_core::sv2_api
miner-apps/translator/src/lib/sv1/sv1_server/downstream_message_handler.rs
Outdated
Show resolved
Hide resolved
The UserIdentity TLV field has a protocol-specified maximum of 32 bytes. When downstream miners send mining.authorize with long worker names, the translator would panic on unwrap(). This fix: - Rejects mining.authorize if the username portion (before the dot) exceeds 32 bytes, as this indicates an invalid configuration - Truncates only the worker name portion if the total length exceeds 32 bytes, preserving the username - Adds defensive error handling in sv1_server.rs as a fallback
Byte-slicing a string (e.g., &name[..32]) can panic if the index falls within a multi-byte UTF-8 character. Use is_char_boundary() to find a safe truncation point. Also removes an unnecessary .clone() on String.
8acdf30 to
9583132
Compare
|
I think we have some misconceptions, and that's probably due to how we called and managed some fields in the We currently have Here the changes I would apply:
Does it make sense to you @average-gary ? |
The UserIdentity TLV field has a protocol-specified maximum of 32 bytes. When downstream miners send mining.authorize with long worker names, the translator would panic on unwrap().
This fix: