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

org.owasp.esapi.ESAPI singletons in 1.4 are not thread-safe #152

Closed
meg23 opened this issue Nov 13, 2014 · 11 comments
Closed

org.owasp.esapi.ESAPI singletons in 1.4 are not thread-safe #152

meg23 opened this issue Nov 13, 2014 · 11 comments

Comments

@meg23
Copy link

meg23 commented Nov 13, 2014

From patrick....@gmail.com on August 25, 2010 20:36:59

There is no synchronization on the 1.4 branch in the ESAPI class with respect to getting and setting the various singletons within it.

This has lead to some live-lock 100% CPU usage conditions for us when the HTMLEntityCodec.initializeMaps() call is run by multiple threads in parallel as a result of the DefaultEncoder constructor being run in parallel.

The lack of synchronization could lead to some threads seeing partially constructed objects and other nastiness.

I have attached a patch against r1465 on the 1.4 branch which adds a lock to each singleton to address this issue.

The additional locks are used rather than synchronizing the methods so that the locking protocol cannot be interfered with by external code and to allow separate portions of the ESAPI library to initialize in parallel.

Attachment: 0002-Made-org.owasp.esapi.ESAPI-singletons-thread-safe.patch

Original issue: http://code.google.com/p/owasp-esapi-java/issues/detail?id=142

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From manico.james@gmail.com on November 02, 2010 01:09:00

Thank you for this Patrick. We will apply this to 1.4 before the next release.

Labels: Milestone-Release1.4

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From skwee...@gmail.com on August 03, 2011 16:49:07

Is this fix in the 2.0 GA release (or later)?

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From wettstei...@gmail.com on August 18, 2011 05:20:04

The singletons are implemented using a double-checking mechanism and a volatile reference variable. This approach is thread-safe for JDK 1.5 and higher, but it is not for previous versions (see http://java.dzone.com/articles/design-patterns-revisited-1-si ). Therefore I would recommend to use a static instance variable (has the additional benefit of less lines of code) or if performance is a concern to use the "initialization-on-demand-idiom" ( http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom )

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From patrick....@gmail.com on August 18, 2011 06:35:48

Were you referring to the patch or to what's in the 1.4 source control repository? I haven't checked the source repo but the patch does not use volatiles. It synchronizes on a lock before doing any checking, which is what 1.4 requires to do lazy initialization without introducing a holder class.

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From wettstei...@gmail.com on August 31, 2011 08:41:01

I was talking about the actual code in the trunk (see DefaultEncoder for example)

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From nemi5...@gmail.com on August 07, 2012 11:48:32

We are experiencing this issue. What do you suggest since it does not look like this will be fixed any time soon?

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From patrick....@gmail.com on August 07, 2012 12:38:48

nemi5150: you can apply my patch (attached to this issue).

wettstein.frank: I don't understand your comment. The patch is against the 1.4 branch, not trunk, and already uses static instance variables. Perhaps the initialization-on-demand-idiom would be best here, but it's more complex. I assume the patch was never applied because of your concerns, but I don't understand how they are relevant to the 1.4 branch.

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From nemi5...@gmail.com on August 07, 2012 13:36:14

Patrick, I have looked at your patch, but it does not seem to be addressing the root cause of the problem. Isn't the root cause that a constructor is initializing a static variable? This is straight from do-not-do 101. I do not understand why this static variable is not initialized in a static block? That way it will only ever be initialized once and only when the class is loaded the first time by the classloader.

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From nemi5...@gmail.com on August 07, 2012 13:40:02

Wait, I see. Maybe you should reopen issue 143 ? It may be fixed in a later build, but 1.4.4 is the latest stable, correct? If so, then 1.4.5 needs to be stabilized. 1.4.5 in Early Release Only since Aug-2010? Really?

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From patrick....@gmail.com on August 08, 2012 12:29:06

I was using ESAPI for output encoding only, and switched to the OWASP Reform library. If you only need encoding, I would check it out: https://www.owasp.org/index.php/Category:OWASP_Encoding_Project

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From kevin.w.wall@gmail.com on September 01, 2014 17:35:13

This issue is already fixed in ESAPI 2.x and ESAPI 1.4.x is no longer supported. Even if this issue were to be fixed in ESAPI 1.4.x, it would still leave many other bugs--some of which are security issues--as unfixed. Therefore, this bug nor any others that are specific to ESAPI 1.4.x, will be fixed.

Status: WontFix
Owner: kevin.w.wall@gmail.com

@meg23 meg23 closed this as completed Nov 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant