8000 Checkstyle Security - SecureRandom, non-static nested classes & final clone() by mmoayyed · Pull Request #802 · apereo/cas · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Checkstyle Security - SecureRandom, non-static nested classes & final clone() #802

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

Merged
merged 8 commits into from
Dec 17, 2014
Merged

Checkstyle Security - SecureRandom, non-static nested classes & final clone() #802

merged 8 commits into from
Dec 17, 2014

Conversation

mmoayyed
Copy link
Member

So this pull addresses checkstyle security issues (actually, there is no inherent checks in CS for these so I came up with custom rules). All 3 of the following categories pertain to "security". Nothing serious, more like hardening the code:

  1. making sure all nested classes are marked as static [about 9-10 instances, mostly in tests]
  2. clone() methods marked as final [one instance]
  3. Use SecureRandom instead of Random() [one instance]

Review should be pretty easy on the eye as the changes are fairly minimal. In some areas (tests specifically) I had to dance around the code a bit to make sure the now-made-static inner classes still would function without the access to the parent's fields.

@mmoayyed mmoayyed added this to the 4.1 milestone Dec 10, 2014
@mmoayyed mmoayyed changed the title Checkstyle Security - SecureRandom, non-static nester & final clone() Checkstyle Security - SecureRandom, non-static nested classes & final clone() Dec 11, 2014
@leleuj
Copy link
Contributor
leleuj commented Dec 11, 2014

I don't understand the reasons behind the two first points and how it is related tos ecurity. Could you elaborate a little more?

import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

didn't you just comment on imports like this earlier? :-p

8000
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed it. 1 - 1 ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Static imports being the key difference here :) We are just loading one class here only anyway, to make the VM super happy!

Copy link
Member Author

Choose a reason for hiding this comment

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

In other words: star static method imports? Goooooood. star import on classes? Baaad. :)

@mmoayyed
Copy link
Member Author

@leleuj A bit of elaboration on the first two:

  • A non-static nested class (note that there really is no such thing as an inner class) has access to all the fields of the enclosing class directly, which allows it to modify program state, albeit accidentally, thus potentially causing security issues. By passing the container, you force the nested class to go through the public contract.

(Also in the event that the nested class is public and non-static, creating instances of it generally lead to perf issues, because you'd require an object of the enclosing class before you can get to the nested class).

  • Generally, it's a good idea to mark the class that has a clone() method as final, AND the method itself because clone() has the ability to construct objects without going through the ctor and if you allow cloning in subclasses, you risk chances of data corruption which my tool tends to want to categorize that as a security issue. (In fact, I bet I can make CS to check for this too)

@leleuj
Copy link
Contributor
leleuj commented Dec 12, 2014

Point 1 makes sense.

For point 2, if I make the clone method final: how I can override it properly in the subclasses?

Conflicts:
	cas-server-core/src/test/java/org/jasig/cas/ticket/registry/DistributedTicketRegistryTests.java
	cas-server-support-jdbc/src/test/java/org/jasig/cas/ticket/registry/JpaTicketRegistryTests.java
	cas-server-support-jdbc/src/test/java/org/jasig/cas/ticket/registry/support/JpaLockingStrategyTests.java
@mmoayyed
Copy link
Member Author
mmoayyed commented 8000 Dec 12, 2014

You can't, and you shouldn't. What you would choose instead is either a copy constructor or a static factory (which how RegisteredService instances are created)

@mmoayyed
Copy link
Member Author

Assuming folks are OK with the changeset, I plan to merge by tomorrow evening EDT.

mmoayyed pushed a commit that referenced this pull request Dec 17, 2014
Checkstyle Security - SecureRandom, non-static nested classes & final clone()
@mmoayyed mmoayyed merged commit e3cd64e into apereo:master Dec 17, 2014
@mmoayyed mmoayyed deleted the checkstyle-security-issues branch December 17, 2014 19:33
Conflicts:
	cas-server-core/src/test/java/org/jasig/cas/ticket/registry/DistributedTicketRegistryTests.java
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.

4 participants
0