Skip to content

data.go: introduced DeviceID formats.#378

Merged
Sandertv merged 28 commits intoSandertv:masterfrom
TrippleAWap:master
Feb 5, 2026
Merged

data.go: introduced DeviceID formats.#378
Sandertv merged 28 commits intoSandertv:masterfrom
TrippleAWap:master

Conversation

@TrippleAWap
Copy link
Contributor

Introduces validation for string fields, array sizes, and device IDs in ClientData to prevent malformed or malicious input. Device ID validation now supports multiple formats based on device model, including GUID, Base64, and BigInt hex. These checks help prevent server crashes and ensure data integrity.

Introduces validation for string fields, array sizes, and device IDs in ClientData to prevent malformed or malicious input. Device ID validation now supports multiple formats based on device model, including GUID, Base64, and BigInt hex. These checks help prevent server crashes and ensure data integrity.
Add DeviceIDFormat and DeviceID types to allow for parsing of the DeviceID which can be used by the user to manually validate devices as we currently don't have a large enough dataset to fully document expected formats.

Change default DeviceID to BigInt instead of UUID as it is more standard.

Remove strict DeviceID format checks and instead introduced parsing.
@TrippleAWap TrippleAWap changed the title data.go: Add extensive validation for ClientData data.go: introduced DeviceID formats and added reflection based checks. Jan 5, 2026
@Sandertv
Copy link
Owner

Sandertv commented Jan 5, 2026

I would much rather we do specific checks for each individual field as opposed to blanket checks using reflection. These are slow, hard to read and not as strict as they should be in many places.

@TrippleAWap
Copy link
Contributor Author

I would much rather we do specific checks for each individual field as opposed to blanket checks using reflection. These are slow, hard to read and not as strict as they should be in many places.

that seems fair, i'll remove the reflection based checks then. What about the introduction of DeviceIDFormat?

@Sandertv
Copy link
Owner

Sandertv commented Jan 5, 2026

Definitely not opposed to more documentation and checks on the device ID. I think the introduction of DeviceIDFormat is a good idea.

Changed methods to take a reference as copying is expensive.
Added length restrictions so we don't do expensive checks that most likely aren't needed. Without this a targeted attack could easily abuse this check.
@TrippleAWap TrippleAWap changed the title data.go: introduced DeviceID formats and added reflection based checks. data.go: introduced DeviceID formats and persona related checks. Jan 5, 2026
@TrippleAWap
Copy link
Contributor Author

Now the current structure I have for the errors related to validating the persona isn't something I believe you'd be happy with merging but I honestly don't know how I should structure this. If you could let me know I'll gladly change it!

Updated DeviceIDFormat enum to distinguish between upper and lower hex string formats, removed BigInt format, and improved the DeviceID.Format() method to more accurately detect device ID formats based on decoded length and character case. Updated documentation to clarify mapping between DeviceOS and DeviceIDFormat.
@TrippleAWap

This comment was marked as resolved.

TrippleAWap and others added 4 commits January 9, 2026 16:19
Changed BuildPlatform fields in AddPlayer and PlayerListEntry structs from int32 to the DeviceOS type for improved type safety and clarity. Updated related marshaling code and imports accordingly.
@TrippleAWap
Copy link
Contributor Author

I'm happy with how this is now, if you have anything you would like me to change please let me know!

@TrippleAWap TrippleAWap changed the title data.go: introduced DeviceID formats and persona related checks. data.go: introduced DeviceID formats. Jan 10, 2026
Reverted protocol changes.
Updated DeviceID format validation to check for 16-byte hex strings.
Cleaned up imports and improved comments for clarity.

PS. All checks have now been tested with a test file that was later removed.
Added a descriptive comment above the Format method of DeviceID to clarify its purpose and behavior.
@TrippleAWap
Copy link
Contributor Author

TrippleAWap commented Jan 12, 2026

Everything here should be good now, let me know if there's anything else! :)

Introduces DeviceIDFormatUnknown to distinguish undetermined formats from invalid ones. Updates the Format method to return Unknown when no format is matched and Invalid when constraints are not met. Adds a String method for DeviceIDFormat and an Expected method to determine the expected DeviceID format based on DeviceOS.
@TrippleAWap
Copy link
Contributor Author

Last commit was more of a QOL change, if you guys have any issues with it let me know!

Changed Conn.ClientData to return a pointer to ClientData. Refactored DeviceIDFormat to remove the Unknown variant, updated String() and Format() methods to use Invalid as the default for unknown formats, and adjusted related logic for consistency.
TrippleAWap and others added 12 commits January 12, 2026 07:48
Updated the DeviceIDFormat.String() method to return 'Invalid' instead of 'Unknown' for unrecognized values, ensuring consistency in error handling.
Introduces a ShouldAccept function field to the Listener struct, allowing custom logic to accept or reject incoming connections. If ShouldAccept is set and returns false, the connection is rejected and a log message is printed.
The 'log' package import was unused in minecraft/listener.go and has been removed to clean up the code.
Copy link
Owner

@Sandertv Sandertv left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@Sandertv Sandertv merged commit b88a076 into Sandertv:master Feb 5, 2026
1 check 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.

3 participants