pmd / pmd/pmd

[java] Enhance ConstructorCallsOverridableMethod to account for clone and readObjectxxx during object construction

Open
#2,989 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

an:enhancement
Dominant language
Java
Stars
5.5k
Forks
1.6k
Avg merge
1d 19h
Merged PRs (30d)
54

Description

Is your feature request related to a problem? Please describe.

https://www.oracle.com/java/technologies/javase/seccodeguide.html#7-4

Guideline 7-4 / OBJECT-4: Prevent constructors from calling methods that can be overridden

"Constructors that call overridable methods give attackers a reference to this (the object being constructed) before the object has been fully initialized. Likewise, clone, readObject, or readObjectNoData methods that call overridable methods may do the same. The readObject methods will usually call java.io.ObjectInputStream.defaultReadObject, which is an overridable method."

Describe the solution you'd like

Add the following boolean properties to check for clone and readObjectxxx methods.

checkCloneMethod
checkReadObjectMethods

Should this rule be customizable via properties?
Yes. See above.

Describe alternatives you've considered
None

Additional context
The rule could be renamed to AvoidOverridableMethodsInObjectConstruction and moved to category Security.

Referred from: https://github.com/pmd/pmd/issues/2988

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ConstructorCallsOverridableMethod rule and review the Oracle secure-coding guidance linked in the issue, along with the referred issue #2988. Done means the rule supports configurable checkCloneMethod and checkReadObjectMethods properties and accounts for clone, readObject, and readObjectNoData during object construction; consider the proposed rename and Security category as part of the scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.