ExMCP.Security.TokenHandler (ex_mcp v0.9.2)
View SourceHandles token processing and sanitization of requests.
This module is responsible for tasks like checking for token passthrough, classifying URLs, and stripping sensitive headers from requests.
Summary
Functions
Checks for and prevents token passthrough to external resources.
Classifies a URL as :internal or :external based on trusted origins.
Extracts the origin (scheme://host:port) from a URL string.
Strips sensitive headers if the resource classification is :external.
Functions
@spec check_token_passthrough(String.t(), [{String.t(), String.t()}], map()) :: {:ok, [{String.t(), String.t()}]}
Checks for and prevents token passthrough to external resources.
It classifies the URL, and if it's external, it strips sensitive headers. This is a key part of preventing confused deputy attacks.
Classifies a URL as :internal or :external based on trusted origins.
Trusted origins are hosts that are considered part of the same security
domain. Wildcard matching (*.example.com) is supported for subdomains.
Extracts the origin (scheme://host:port) from a URL string.
@spec strip_sensitive_headers([{String.t(), String.t()}], :internal | :external) :: [ {String.t(), String.t()} ]
Strips sensitive headers if the resource classification is :external.