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 c0c5195 commit a31e1ec
Showing 1 changed file with 9 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.http.entity.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 @@ -41,6 +43,7 @@
*/
public abstract class BaseExtensionRestHandler implements ExtensionRestHandler {

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

/**
Expand Down Expand Up @@ -77,6 +80,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 a31e1ec

Please sign in to comment.