This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-5ee4f861-b9ea-4ef1-bf48-f7f8a5e0154d XWIKI-25747 Open

PasswordClass throws a shared static exception whose stack trace points to XWiki initialization instead of the actual caller

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-16b68063-e642-432a-8d7d-9310f6829847 Thomas Mortagne created this issue on 12/Nov/26 17:31
 
Summary: PasswordClass throws a shared static exception whose stack trace points to XWiki initialization instead of the actual caller
Issue Type: cid:jira-generated-image-avatar-5ee4f861-b9ea-4ef1-bf48-f7f8a5e0154d Bug
Affects Versions: 17.10.14, 18.4.5, 18.8.0-rc-1
Assignee: Unassigned
Components: Old Core
Created: 12/Nov/26 17:31
Priority: cid:jira-generated-image-static-major-159d9899-fa78-4e02-8150-b2723a623ed9 Major
Reporter: Thomas Mortagne
Description:

PasswordClass creates the IllegalArgumentException it throws for an unknown encoded password format once, in a static field, instead of where the error happens:

private static final IllegalArgumentException ILLEGAL_ARGUMENT_EXCEPTION_UNKNOWN_FORMAT =
    new IllegalArgumentException("The provided encoded password doesn't match any known hash "
        + "encoded password format.");

That same instance is then thrown by getAlgorithmFromPassword(String) and arePasswordsMatching(String, String). A Java exception's stack trace is captured when it is constructed, so every log of this error shows the stack of whatever first loaded PasswordClass, typically the XWiki initialization thread, and never the code that actually passed the unknown password value.

Example

The OIDC provider's userinfo endpoint failing on an XWiki 17.10.15 instance logs:

[http-nio-8080-exec-10 - http://intra.example.org/xwiki/oidc/userinfo] DEBUG i.OIDCResourceReferenceHandler - Failed to handle the OIDC endpoint
java.lang.IllegalArgumentException: The provided encoded password doesn't match any known hash encoded password format.
	at com.xpn.xwiki.objects.classes.PasswordClass.<clinit>(PasswordClass.java:207)
	at com.xpn.xwiki.objects.meta.PasswordMetaClass.getInstance(PasswordMetaClass.java:103)
	at com.xpn.xwiki.internal.filter.output.PropertyClassOutputFilterStream.beginWikiClassProperty(PropertyClassOutputFilterStream.java:109)
	...
	at com.xpn.xwiki.store.XWikiHibernateStore.loadXWikiDoc(XWikiHibernateStore.java:1117)
	...
	at com.xpn.xwiki.XWiki.initializeMandatoryDocuments(XWiki.java:1412)
	at com.xpn.xwiki.XWiki.initXWiki(XWiki.java:1340)
	...
	at com.xpn.xwiki.internal.XWikiInitializerJob.runInternal(XWikiInitializerJob.java:103)

The request runs on an HTTP thread, but the logged stack is the startup one. It suggests that PasswordClass failed to initialize, while the exception was in fact thrown much later, from arePasswordsMatching called through the OIDC consent store's access token check. Finding the real caller requires reading the code, and there is no way to know which stored value or which document is involved.

Expected

A new exception is created at each throw, so that its stack trace shows the actual caller. Ideally its message also gives some context, for example the location of the property, when known, but never the password value itself.

A shared, mutable exception instance has other drawbacks: any code calling addSuppressed or initCause on it (try-with-resources, wrapping) modifies the one instance used by every thread for the lifetime of the JVM.