Repository navigation
CDAP-21270: Enable JEXL expressions allowlisting in Wrangler Directives #1040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
wrangler-api/src/main/java/io/cdap/wrangler/api/DefaultJexlAllowlist.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright © 2026 Cask Data, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
|
|
||
| package io.cdap.wrangler.api; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * Defines the set of classes allowed in the JEXL Sandbox by default. | ||
| */ | ||
| public final class DefaultJexlAllowlist { | ||
|
|
||
| private static final List<String> DEFAULT_CLASSES = Arrays.asList( | ||
| // Data types | ||
| "java.lang.Boolean", "java.lang.Byte", "java.lang.Character", "java.lang.Double", "java.lang.Float", | ||
| "java.lang.Integer", "java.lang.Long", "java.lang.Short", | ||
|
|
||
| // Strings | ||
| "java.lang.String", "java.lang.StringBuilder", "java.util.StringJoiner", | ||
|
|
||
| // Math | ||
| "java.lang.Math", "java.math.BigDecimal", "java.math.BigInteger", | ||
|
|
||
| // Time | ||
| "java.time.ZonedDateTime", "java.time.LocalDate", "java.time.LocalDateTime", "java.time.Instant", | ||
| "java.time.Duration", "java.time.format.DateTimeFormatter", | ||
|
|
||
| // Utilities | ||
| "java.util.Arrays", "java.util.Collections", "java.util.UUID", "java.util.Base64"); | ||
|
|
||
| private static final List<JexlAllowlist> ALLOWLIST = Collections.unmodifiableList( | ||
| DEFAULT_CLASSES.stream() | ||
| .map(className -> { | ||
| return new JexlAllowlist( | ||
| className, | ||
| Collections.singletonList(JexlAllowlist.INCLUDE_ALL_WILDCARD), | ||
| Collections.singletonList(JexlAllowlist.INCLUDE_ALL_WILDCARD)); | ||
| }) | ||
| .collect(Collectors.toList())); | ||
|
|
||
| private DefaultJexlAllowlist() { | ||
| } | ||
|
|
||
| /** | ||
| * @return the list of default allowed classes. | ||
| */ | ||
| public static List<JexlAllowlist> get() { | ||
|
riyaa14 marked this conversation as resolved.
vsethi09 marked this conversation as resolved.
|
||
| return ALLOWLIST; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
wrangler-api/src/main/java/io/cdap/wrangler/api/DirectiveConfigDeserializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright © 2026 Cask Data, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
|
|
||
| package io.cdap.wrangler.api; | ||
|
|
||
| import com.google.gson.JsonDeserializationContext; | ||
| import com.google.gson.JsonDeserializer; | ||
| import com.google.gson.JsonElement; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonParseException; | ||
| import com.google.gson.reflect.TypeToken; | ||
|
|
||
| import java.lang.reflect.Type; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Custom GSON deserializer for {@link DirectiveConfig}. | ||
| */ | ||
| public final class DirectiveConfigDeserializer implements JsonDeserializer<DirectiveConfig> { | ||
| private static final Type STRING_SET_TYPE = new TypeToken<Set<String>>() { }.getType(); | ||
| private static final Type STRING_MAP_TYPE = new TypeToken<Map<String, String>>() { }.getType(); | ||
| private static final Type JEXL_ALLOWLIST_LIST_TYPE = new TypeToken<List<JexlAllowlist>>() { }.getType(); | ||
|
|
||
| @Override | ||
| public DirectiveConfig deserialize(JsonElement configJson, Type typeOfT, JsonDeserializationContext ctx) | ||
| throws JsonParseException { | ||
| JsonObject configJsonObj = configJson.getAsJsonObject(); | ||
|
|
||
| return new DirectiveConfig( | ||
| deserializeProperty(configJsonObj, DirectiveConfig.EXCLUSIONS_KEY, STRING_SET_TYPE, ctx), | ||
| deserializeProperty(configJsonObj, DirectiveConfig.ALIASES_KEY, STRING_MAP_TYPE, ctx), | ||
| deserializeProperty(configJsonObj, DirectiveConfig.JEXL_ALLOWLIST_KEY, JEXL_ALLOWLIST_LIST_TYPE, ctx)); | ||
| } | ||
|
|
||
| @Nullable | ||
| private static <T> T deserializeProperty(JsonObject obj, String key, Type type, JsonDeserializationContext ctx) { | ||
| JsonElement element = obj.get(key); | ||
| return (element != null && !element.isJsonNull()) ? ctx.deserialize(element, type) : null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
wrangler-api/src/main/java/io/cdap/wrangler/api/DirectiveJexlAllowlist.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright © 2026 Cask Data, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
|
|
||
| package io.cdap.wrangler.api; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * This interface {@link DirectiveJexlAllowlist} provides a way to get JEXL | ||
| * configuration. | ||
| */ | ||
| public interface DirectiveJexlAllowlist { | ||
|
|
||
| /** | ||
| * Gets the list of JEXL inclusions. | ||
| * | ||
| * @return the list of JEXL inclusions | ||
| */ | ||
| @Nullable | ||
| List<JexlAllowlist> getJexlAllowlist(); | ||
|
|
||
| /** | ||
| * Checks if JEXL allowlisting is enabled. | ||
| * | ||
| * @return true if JEXL allowlisting is enabled, false otherwise. | ||
| */ | ||
| boolean isJexlAllowlistEnabled(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.