Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 2 min read

Preserving Prompt Caching and Blocking Bedrock IAM Cost Bombs in

When teams connect AI agents to Amazon Bedrock or Claude, two cost spikes show up quickly in production: random PII redaction silently breaking prompt caching, and overly broad Bedrock IAM policies letting dev roles invo

When teams connect AI agents to Amazon Bedrock or Claude, two cost spikes show up quickly in production: random PII redaction silently breaking prompt caching, and overly broad Bedrock IAM policies letting dev roles invoke expensive models or Provisioned Throughput.

Both have straightforward fixes that take less than 15ms to enforce.

1. Why random PII placeholders kill your 90% prompt-cache discount

Prompt caching on Amazon Bedrock and Anthropic requires a byte-for-byte identical prefix across requests.

If your redaction middleware substitutes <EMAIL_8f2a> on request one and <EMAIL_c19d> on request two for the same cached system/RAG context, every request misses the cache and bills at full input token rates.

CoreNova AI Guard (PUBLIC on AWS Marketplace, $29/$99/$299/mo, zero data retention) avoids this by generating deterministic positional placeholders ([EMAIL_1], [CREDIT_CARD_1], [AWS_ACCESS_KEY_1]):

curl -s -X POST https://guard.corenovacloud.com/v1/redact \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Account owner [email protected] reported ticket #4021; escalate to [email protected].",
    "return_restoration_map": true
  }'

For repeated entities across multi-turn MCP tool responses, McpToolResponseGuard maintains a session map so [email protected] stays [EMAIL_1] across turns while restore_for_tool() only restores real values into allowlisted tools and fields.

2. Catching Bedrock IAM cost bombs before Terraform apply

Most IAM scanners check for iam:* or s3:*, but skip Amazon Bedrock cost-commitment actions. A role created by a coding agent with bedrock:* or bedrock:CreateProvisionedModelThroughput on Resource: "*" can lock an account into thousands of dollars of hourly commitment or let a looping agent invoke arbitrary foundation models.

We just shipped v1.4.0 of CoreNova Cloud IAM & IaC Security Audit (PUBLIC on AWS Marketplace, https://audit.corenovacloud.com) with four deterministic Bedrock checks across IAM JSON, Terraform, and CloudFormation:

  • IAM_BEDROCK_COST_COMMITMENT (CRITICAL): flags bedrock:*, CreateProvisionedModelThroughput, UpdateProvisionedModelThroughput, CreateModelCustomizationJob, and CreateModelImportJob on Resource: "*" without conditions.
  • IAM_BEDROCK_UNSCOPED_INVOKE (HIGH): flags bedrock:InvokeModel*, Converse*, and InvokeAgent on * or foundation-model/* without explicit model/inference-profile ARN scoping.
  • IAC_BEDROCK_PROVISIONED_THROUGHPUT (HIGH): flags aws_bedrock_provisioned_model_throughput and AWS::Bedrock::ProvisionedModelThroughput in PR diffs for FinOps sign-off.
  • IAC_BEDROCK_WILDCARD_INVOKE (HIGH): flags inline Terraform/CloudFormation IAM blocks granting bedrock:InvokeModel* on *.

Test it against the live zero-retention endpoint:

curl -s -X POST https://audit.corenovacloud.com/v1/scan/iam \
  -H "Content-Type: application/json" \
  -d '{
    "policy": {
      "Statement": [{
        "Sid": "DevBedrockAccess",
        "Effect": "Allow",
        "Action": ["bedrock:InvokeModel", "bedrock:CreateProvisionedModelThroughput"],
        "Resource": "*"
      }]
    }
  }'

Scope Resource to explicit model ARNs such as arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-haiku-20241022-v1:0 and it passes with action: "allow" and findings_count: 0.

Try both via Streamable HTTP MCP or AWS Marketplace

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.