中文版本:chinese edition
Summary
Affected Versions: Nexus Repository Manager 3.6.2 OSS/Pro versions up to and including 3.14.0
Fixed in Version: Nexus Repository Manager OSS/Pro version 3.15.0
Nice find from Rico @ Tencent Security Yunding Lab and voidfyoo @ Chaitin Tech
Analysis
In plugins/nexus-coreui-plugin/src/main/java/org/sonatype/nexus/coreui/ComponentComponent.groovy:185
Nexus introduced CSEL based selectors to support changes coming in future releases. CSEL is a light version of JEXL used to script queries along specific paths and coordinates available to your repository manager formats. Step in browseService.previewAssets
,and its implementations in components/nexus-repository/src/main/java/org/sonatype/nexus/repository/browse/internal/BrowseServiceImpl.java:233
Pay attention to the comment: whereClause
will run after repository filtering! We need to know how it is constructed. In the components/nexus-repository/src/main/java/org/sonatype/nexus/repository/browse/internal/PreviewAssetsSqlBuilder.java:51
, which introduce contentExpression
and jexlExpression
:
So after repository filtering,whereClause
will run automatically which call contentExpression.execute()
method 。In components/nexus-repository/src/main/java/org/sonatype/nexus/repository/selector/internal/ContentExpressionFunction.java
According to the code contentExpression(@this, :jexlExpression, :repositorySelector, " +":repoToContainedGroupMap) == true
, you can map contentExpression parameters to iParams[i]
:
@this
->iParams[0]
jexlExpression
->iParams[1]
repositorySelector
->iParams[2]
In last, it will call checkJexlExpression()
method:
|
|
So, we can step in selectorManager.evaluate
,which is implemented in components/nexus-core/src/main/java/org/sonatype/nexus/internal/selector/SelectorManagerImpl.java:156
,and finally evaluate the expression:
@Override
@Guarded(by = STARTED)
public boolean evaluate(final SelectorConfiguration selectorConfiguration, final VariableSource variableSource)
throws SelectorEvaluationException
{
Selector selector = createSelector(selectorConfiguration);
try {
return selector.evaluate(variableSource);
}
catch (Exception e) {
throw new SelectorEvaluationException("Selector '" + selectorConfiguration.getName() + "' evaluation in error",
e);
}
}
Reproducible steps
According to DOCS:
https://help.sonatype.com/repomanager3/configuration/repository-management#RepositoryManagement-CreatingaQuery
To reproduce the issue successfully, we need upload some assets to the repo firstly。For excample, upload a jar:
Then go here to intercept the request:
POC:
Fix
Add the permission requirement: @RequiresPermissions('nexus:selectors:*')