Skip to content

AgentCore Gateway MCP returns "authorization denied" when tool input contains localhost URLs

0

I'm using Amazon Bedrock AgentCore Gateway with MCP protocol to expose Lambda-based tools to Claude. When my ingest_text tool receives text content that happens to contain http://localhost URLs (e.g., documentation with code examples), the Gateway returns "authorization denied" before the request reaches my Lambda.

Setup: Gateway with CUSTOM_JWT authorizer (Cognito) Lambda target with MCP tools Tool: ingest_text that accepts a text string parameter To reproduce: Call ingest_text with text containing http://localhost:8000 Gateway returns "authorization denied"

Expected behavior: Text content in tool parameters should pass through to Lambda without URL scanning. The text is just data to store, not a URL to fetch. Workaround found: Direct Lambda invocation (bypassing Gateway) works fine with the same payload. The issue is specifically in the Gateway's request processing.

Is there a way to disable URL scanning for tool input parameters, or is this a bug?

1 Answer
-1

This issue appears to be related to how AgentCore Gateway handles security for incoming requests that contain URLs, particularly localhost URLs which might be flagged as a security concern.

The most flexible way to address this is by implementing a gateway interceptor. Gateway interceptors provide fine-grained access control and can be used to modify or filter requests based on user context. A REQUEST interceptor executes before the gateway makes a call to the target Lambda, allowing you to implement custom logic that can validate and potentially modify the content before it reaches the authorization check that's blocking your localhost URLs.

To solve your specific issue:

  1. Create an interceptor Lambda function that can inspect and potentially modify the request payload.
  2. Configure this interceptor in your AgentCore Gateway using the UpdateGateway API with an authorizerConfiguration that includes your interceptor.
  3. In your interceptor, you could implement logic to either:
  • Sanitize the localhost URLs in the text content
  • Add special authorization logic to allow these specific patterns
  • Forward token details from the interceptor to your tool

This approach allows you to maintain security while handling the specific case of documentation text that contains localhost URLs as examples.

Alternatively, you might want to check if there are any policies applied to your gateway that are specifically blocking localhost URLs. AgentCore Policy evaluates whether tool calls are allowed or denied, and there might be a default policy blocking URLs that appear to be accessing local resources.
Sources
How to route pass through an access token in AWS Bedrock AgentCore? | AWS re:Post
Fine-grained access control for Amazon Bedrock AgentCore Gateway - Amazon Bedrock AgentCore
Use a AgentCore Gateway with AgentCore Policy - Amazon Bedrock AgentCore

answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.