Skip to content

[Code Quality] User input reflected on error #3990

@rithin-pullela-aws

Description

@rithin-pullela-aws

Some error cases cause the service to reflect user input in error messages. Reflected user input could be a security concern.

Following APIs expose user input:
1. Create MCP Connector:
i. protocol

POST /_plugins/_ml/connectors/_create
{
    "name": "OpenAI Chat Connector",
    "description": "The connector to public OpenAI model service for GPT 3.5",
    "version": 1,
    "protocol": "httpxyz", <--- Protocol field in question
    "parameters": {
        "endpoint": "api.openai.com",
        "model": "gpt-3.5-turbo"
    },
    "credential": {
        "openAI_key": "..."
    },
    "actions": [
        {
            "action_type": "predict",
            "method": "POST",
            "url": "https://${parameters.endpoint}/v1/chat/completions", 
            "headers": {
                "Authorization": "Bearer ${credential.openAI_key}"
            },
            "request_body": "{ \"model\": \"${parameters.model}\", \"messages\": ${parameters.messages} }"
        }
    ]
}

Error when wrong protocol is sent:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Can't find class for type httpxyz"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Can't find class for type httpxyz"
    },
    "status": 400
}

2. Register Agent:
i. type

POST /_plugins/_ml/agents/_register
{
  "name": "Test_Agent_For_RAG",
  "type": "wronng_type", <-------- Type Field in question
  "description": "this is a test agent",
  "tools": [
    {
      "name": "vector_tool",
      "type": "VectorDBTool",
      "parameters": {
        "model_id": "zBRyYIsBls05QaITo5ex",
        "index": "my_test_data",
        "embedding_field": "embedding",
        "source_field": [
          "text"
        ],
        "input": "${parameters.question}"
      }
    },
    {
      "type": "MLModelTool",
      "description": "A general tool to answer any question",
      "parameters": {
        "model_id": "NWR9YIsBUysqmzBdifVJ",
        "prompt": "\n\nHuman:You are a professional data analyst. You will always answer question based on the given context first. If the answer is not directly shown in the context, you will analyze the data and find the answer. If you don't know the answer, just say don't know. \n\n Context:\n${parameters.vector_tool.output}\n\nHuman:${parameters.question}\n\nAssistant:"
      }
    }
  ]
}

Error when wrong type is sent is sent:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "wronng_type is not a valid Agent Type"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "wronng_type is not a valid Agent Type"
    },
    "status": 400
}

3. Register MCP Tools:
i. name: When a duplicate name is provided error shows the name of the tool

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Unable to register tools: [ListIndexTool_ClusterA] as they already exist"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Unable to register tools: [ListIndexTool_ClusterA] as they already exist"
    },
    "status": 400
}

ii. type:when wrong type is provided the error shows the type of the tool provided as input

{
    "error": {
        "root_cause": [
            {
                "type": "action_request_validation_exception",
                "reason": "Validation Failed: 1: Unrecognized tool in request: [ListIndexTool_1];"
            }
        ],
        "type": "action_request_validation_exception",
        "reason": "Validation Failed: 1: Unrecognized tool in request: [ListIndexTool_1];"
    },
    "status": 400
}

General MCP Tool registration body:

POST /_plugins/_ml/mcp/tools/_register
{
  "tools": [
    {
      "type": "WebSearchTool",
      "name": "GoogleSearchTool",
      "attributes": {
        "input_schema": {
          "type": "object",
          "properties": {
            "engine": {
              "type": "string",
              "description": "The search engine that will be used by the tool."
            },
            "query": {
              "type": "string",
              "description": "The search query parameter that will be used by the engine to perform the search."
            },
            "next_page": {
              "type": "string",
              "description": "The search result's next page link. If this is provided, the WebSearchTool will fetch the next page results using this link and crawl the links on the page."
            }
          },
          "required": [
            "engine",
            "query"
          ]
        },
        "strict": false
      }
    }
  ]
}

4. Update MCP Tools
i.type
ii.attributes.additionalProperties

Example request body:

POST /_plugins/_ml/mcp/tools/_update
{
  "type": "PPLTool",
  "name": "TransferQuestionToPPLAndExecuteTool",
  "description": "Use this tool to convert natural language into PPL queries and execute them. Use this tool after you know the index name; otherwise, call IndexRoutingTool first. The input parameters are: {index: IndexName, question: UserQuestion}",
  "parameters": {
    "model_id": "${your_model_id}",
    "model_type": "FINETUNE"
  },
  "attributes": {
    "input_schema": {
      "type": "object",
      "properties": {
        "question": {
          "type": "string",
          "description": "The user's natural language question that needs to be converted to PPL."
        },
        "index": {
          "type": "string",
          "description": "The index on which the generated PPL query will be executed."
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

On-deck

Status

New

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions