Skip to content
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

Incorrect Rule: java/missing-no-arg-constructor-on-serializable #18371

Closed
ben-manes opened this issue Dec 26, 2024 · 3 comments
Closed

Incorrect Rule: java/missing-no-arg-constructor-on-serializable #18371

ben-manes opened this issue Dec 26, 2024 · 3 comments

Comments

@ben-manes
Copy link

ben-manes commented Dec 26, 2024

* @name Serializable but no void constructor
* @description A non-serializable, immediate superclass of a serializable class that does not
* itself declare an accessible, no-argument constructor causes deserialization to
* fail.

This rule does not take into consideration the Serialization Proxy pattern. This approach is recommended in Effective Java, a reference this rule's explanation points to. The proxy pattern is both a simplification and protection from security threats by reconstructing the object from the data elements, using readResolve to replace the output with a new instance, rather than trying to rehydrate the object directly.

While ideally this rule would understand this pattern, it is okay if a false positive yet it recommends that as the solution. A less aware developer might remove this security protection to comply or not be nudged to implement that better approach if a true positive.

@jketema
Copy link
Contributor

jketema commented Dec 27, 2024

Hi @ben-manes,

Thanks for your observation. I've relayed this to the CodeQL Java engineering team.

@smowton
Copy link
Contributor

smowton commented Jan 7, 2025

As of CodeQL 2.20.2 we will no longer flag classes that define writeReplace and so which are assumed to perhaps never be exposed to the default deserialization algorithm and its requirement for an accessible parent-class constructor.

@smowton smowton closed this as completed Jan 7, 2025
@ben-manes
Copy link
Author

Thanks! I’d recommend also updating the rule’s suggested fix to inform the user of the serialization proxy pattern for security reasons. While thankfully native serialization is rare, when required due to legacy compatibility, users should be hinted towards secure practices.

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

No branches or pull requests

3 participants