Skip to content

Commit

Permalink
Adds a validation check for setting extension name
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Jul 10, 2023
1 parent 9023a5a commit 8ee2f54
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.function.Function;

import static org.apache.hc.core5.http.ContentType.APPLICATION_JSON;

import org.opensearch.OpenSearchException;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.extensions.rest.ExtensionRestResponse;
Expand All @@ -43,6 +45,8 @@ public abstract class BaseExtensionRestHandler implements ExtensionRestHandler {

private static String extensionName;

private static final String VALID_EXTENSION_NAME_PATTERN = "^[a-zA-Z0-9:/*_]*$";

/**
* Constant for JSON content type
*/
Expand Down Expand Up @@ -77,6 +81,12 @@ protected List<ReplacedRouteHandler> replacedRouteHandlers() {
}

public void setExtensionName(String extensionName) {
if (extensionName == null || extensionName.isBlank() || !extensionName.matches(VALID_EXTENSION_NAME_PATTERN)) {
throw new OpenSearchException(
"Invalid extension name specified. The extension name may include the following characters"
+ " 'a-z', 'A-Z', '0-9', ':', '/', '*', '_'"
);
}
BaseExtensionRestHandler.extensionName = extensionName;
}

Expand Down

0 comments on commit 8ee2f54

Please sign in to comment.