Skip to content

[cherry-pick][4.10][CDAP-21270] Enable JEXL expressions allowlisting in Wrangler Directives - #1048

Merged
sahusanket merged 1 commit into
release/4.10from
cp-1040
Sep 8, 2026
Merged

sahusanket merged 1 commit into
release/4.10from
cp-1040

Conversation

@riyaa14

@riyaa14 riyaa14 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Cherry pick for #1040

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a JEXL allowlisting mechanism in Wrangler to restrict the classes, methods, and properties that can be executed within JEXL expressions. It updates DirectiveConfig to include allowlist rules, integrates a JexlSandbox during script compilation in EL.java, and propagates compilation options across various directives and service handlers. Feedback on these changes highlights a critical security vulnerability in EL.java where the sandbox permission logic is inverted (incorrectly mapping blocklists and allowlists), as well as a potential NullPointerException in DirectivesHandler.java if the configuration store returns a null configuration.

Comment on lines +195 to +199
JexlSandbox.Permissions permissions = sandbox.permissions(
className,
!rule.blockAllProperties(),
!rule.blockAllProperties(),
!rule.blockAllMethods());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

The logic for configuring JEXL sandbox permissions is inverted. In JEXL 3, JexlSandbox.Permissions uses WhiteSet (allowlist) when the boolean parameter is true, and BlackSet (blocklist) when it is false.

Using !rule.blockAllMethods() means:

  • If blockAllMethods() is true (block all), it passes false (BlackSet) and adds no methods, which actually allows all methods.
  • If allowAllMethods() is true (allow all), it passes true (WhiteSet) and adds no methods, which actually blocks all methods.

This is a critical security vulnerability. It should be changed to use !rule.allowAllProperties() and !rule.allowAllMethods() respectively.

Suggested change
JexlSandbox.Permissions permissions = sandbox.permissions(
className,
!rule.blockAllProperties(),
!rule.blockAllProperties(),
!rule.blockAllMethods());
JexlSandbox.Permissions permissions = sandbox.permissions(
className,
!rule.allowAllProperties(),
!rule.allowAllProperties(),
!rule.allowAllMethods());

Comment on lines +1039 to +1045
DirectiveConfig config = configStore.getConfig();
if (!jexlAllowlistEnabled) {
JsonObject configJson = config.toJson().getAsJsonObject();
configJson.remove(DirectiveConfig.JEXL_ALLOWLIST_KEY);
return new ServiceResponse<>(configJson);
}
return new ServiceResponse<>(config);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If configStore.getConfig() returns null (which is now possible when the database is not initialized), calling config.toJson() will throw a NullPointerException when jexlAllowlistEnabled is false.

We should add a null check and default to DirectiveConfig.EMPTY to make this endpoint robust.

      DirectiveConfig config = configStore.getConfig();
      if (config == null) {
        config = DirectiveConfig.EMPTY;
      }
      if (!jexlAllowlistEnabled) {
        JsonObject configJson = config.toJson().getAsJsonObject();
        configJson.remove(DirectiveConfig.JEXL_ALLOWLIST_KEY);
        return new ServiceResponse<>(configJson);
      }
      return new ServiceResponse<>(config);

@sahusanket
sahusanket merged commit 62631e0 into release/4.10 Sep 8, 2026
2 checks passed
@sahusanket
sahusanket deleted the cp-1040 branch September 8, 2026 14:57
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.

2 participants