Repository navigation
[cherry-pick]][6.10]fix: handle JEXL security violations and fail pipeline immediately - #1057
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces ELPermissionException to handle JEXL sandbox permission violations, ensuring that critical sandbox violations fail the pipeline immediately regardless of the configured on-error strategy. It updates exception handling in EL and Wrangler, and adds helper utilities and unit tests. The review feedback suggests restoring a helpful hint to the ELPermissionException error message to assist users in diagnosing sandbox violations, and replacing the use of Throwables.getCausalChain in WranglerErrorUtil with a safer, more efficient iterative loop to avoid deprecation issues and potential crashes from circular causal chains.
| if (isJexlPermissionViolation(e, allowlistEnabled)) { | ||
| throw new ELPermissionException(baseErrorMessage, e); | ||
| } |
There was a problem hiding this comment.
The error message for ELPermissionException has lost the helpful hint regarding allowlisted classes, methods, and properties. Without this context, users encountering sandbox violations will only see a generic evaluation error, making it difficult to diagnose permission issues. Adding the descriptive suffix back for permission violations restores this critical context.
| if (isJexlPermissionViolation(e, allowlistEnabled)) { | |
| throw new ELPermissionException(baseErrorMessage, e); | |
| } | |
| if (isJexlPermissionViolation(e, allowlistEnabled)) { | |
| throw new ELPermissionException( | |
| baseErrorMessage + " Make sure the JEXL transformation is valid and uses only allowlisted classes, methods, and properties.", e); | |
| } |
| public static boolean isCriticalException(Throwable e) { | ||
| return e != null && Throwables.getCausalChain(e).stream() | ||
| .anyMatch(ELPermissionException.class::isInstance); | ||
| } |
There was a problem hiding this comment.
Using Throwables.getCausalChain(e) is inefficient as it builds a full list of throwables and creates stream overhead on every exception check. Additionally, Throwables.getCausalChain is deprecated in newer Guava versions and can throw an IllegalArgumentException if there is a loop in the causal chain, which would crash the pipeline with an unhandled exception. A simple iterative loop is more efficient, avoids memory allocation, and is safer.
public static boolean isCriticalException(Throwable e) {
Throwable cause = e;
while (cause != null) {
if (cause instanceof ELPermissionException) {
return true;
}
cause = cause.getCause();
}
return false;
}
original pr : #1056
Difference from
develop(#1055)WranglerErrorUtil.java&Wrangler.java:WranglerErrorUtil(introduced in4.11/developviaf26ecd28) did not exist inrelease/4.10because it relies onio.cdap.cdap.api.exception.ErrorUtils/ProgramFailureException, which are only available in CDAP 6.11+ (release/4.10builds against CDAP6.10.8-SNAPSHOTand throws a standardExceptionon pipeline failure).release/4.10,WranglerErrorUtilis added with onlyisCriticalException(Throwable)(to check forELPermissionExceptionin the causal chain), andWrangler.javacontinues to throw the existingExceptionwhenshouldFailPipeline(e)evaluates totrue.