Skip to content

discard introspection data cached against an outdated introspector set - #450

Open
rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:introspection-data-stale-cache
Open

rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:introspection-data-stale-cache

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

PropertyUtilsBean.getIntrospectionData fills descriptorsCache with an unsynchronized get/compute/put, while the three methods that change the registered BeanIntrospector list (addBeanIntrospector, removeBeanIntrospector, resetBeanIntrospectors) invalidate that cache by clearing it (#435). A thread that already entered fetchIntrospectionData when the list changes therefore stores its pre-change result after the clear has run, and nothing invalidates that entry again, so the stale descriptors stay cached for the life of the PropertyUtilsBean.

Registering SuppressPropertiesBeanIntrospector while another thread reads the same bean class consequently leaves the suppressed property readable and writable through getProperty, setProperty and BeanUtilsBean.populate, so the documented CVE-2014-0114 / BEANUTILS-463 hardening fails open. The defaults resetBeanIntrospectors installs (SUPPRESS_CLASS, SUPPRESS_DECLARING_CLASS) sit in the same window, and the shared PropertyUtils singleton is commonly warmed by framework or ORM threads, so the two orders do overlap in practice.

Found by auditing the descriptorsCache invalidation added in #435 for the case where that invalidation and a cache fill overlap.

Reproduced with a single reader thread and no custom introspector, 400 rounds of "start reader, register the suppressor, check whether the suppressed property is still visible":

rounds=400 leaks(suppressed property still present)=347   // before
rounds=400 leaks(suppressed property still present)=0     // after

The fix stamps the introspector-set version before introspecting and conditionally removes the entry again when the version changed while the fetch was running, so the next caller refetches against the current introspectors. clearDescriptors() now routes through clearDescriptorCaches() so it carries the same stamp. Single-threaded behavior is unchanged.

Different root cause from the neighbouring changes in this area: #435 added the missing invalidation (here the invalidation runs and is then undone by an in-flight fetch), #413 / #431 are the mapped-descriptor fallback in getPropertyDescriptor, and #439 / #449 are unrelated to the cache.

PropertyUtilsTest.testAddBeanIntrospectorDuringIntrospectionInvalidatesCache is a deterministic version of the race: a latch-blocking BeanIntrospector holds the fetch open while the suppressor is registered. On master it fails with

Suppressed property should have no descriptor ==> expected: <null> but was: <java.beans.PropertyDescriptor[name=stringProperty; ...]>

and it passes with the change.

Full default goal is green: 1318 tests, 0 failures, 0 errors, apache-rat and checkstyle clean.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

getIntrospectionData fills descriptorsCache with an unsynchronized
get/compute/put, while addBeanIntrospector, removeBeanIntrospector and
resetBeanIntrospectors invalidate that cache by clearing it. A thread
that already entered fetchIntrospectionData when the introspector list
changes stores its pre-change result after the clear has run, and the
entry is never invalidated again, so registering
SuppressPropertiesBeanIntrospector concurrently with a read of the same
bean class leaves the suppressed property readable and writable.

Stamp the introspector-set version before introspecting and remove the
entry again when the version changed while the fetch was running, so the
next caller refetches against the current introspectors. clearDescriptors
now routes through clearDescriptorCaches so it carries the same stamp.
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.

1 participant