File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * ZAP HTTP Sender Script - Add MCP Session ID Header
3+ *
4+ * This script intercepts all outgoing HTTP requests from ZAP
5+ * and adds the Mcp-Session-Id header to enable authenticated scanning.
6+ *
7+ * The session ID is stored as a global variable by the automation framework.
8+ */
9+
10+ function sendingRequest ( msg , initiator , helper ) {
11+ // Get the MCP session ID from global variable
12+ var sessionId = org . zaproxy . zap . extension . script . ScriptVars . getGlobalVar ( 'mcpSessionId' ) ;
13+
14+ if ( sessionId != null && sessionId != '' ) {
15+ // Add the Mcp-Session-Id header to the request
16+ msg . getRequestHeader ( ) . setHeader ( 'Mcp-Session-Id' , sessionId ) ;
17+
18+ // Also ensure we have the Accept header for MCP endpoints
19+ var uri = msg . getRequestHeader ( ) . getURI ( ) . toString ( ) ;
20+ if ( uri . indexOf ( '/mcp' ) !== - 1 ) {
21+ msg . getRequestHeader ( ) . setHeader ( 'Accept' , 'application/json, text/event-stream' ) ;
22+ msg . getRequestHeader ( ) . setHeader ( 'Content-Type' , 'application/json' ) ;
23+ }
24+ }
25+ }
26+
27+ function responseReceived ( msg , initiator , helper ) {
28+ // No action needed on response
29+ }
Original file line number Diff line number Diff line change 11---
22# ZAP Automation Framework Configuration for MCP Protocol
3- # Uses the Replacer add-on to inject Mcp-Session-Id header into all requests
3+ # Uses HTTP Sender script to inject Mcp-Session-Id header into all requests
44
55env :
66 contexts :
1717 progressToStdout : true
1818
1919jobs :
20- # Add the Mcp-Session-Id header to all requests using Replacer
21- - type : replacer
20+ # Store the MCP session ID as a global variable for the HTTP Sender script
21+ - type : script
2222 parameters :
23- rules :
24- - description : " Add MCP Session ID header"
25- enabled : true
26- matchType : REQ_HEADER
27- matchString : " Mcp-Session-Id"
28- replacement : " Mcp-Session-Id: MCP_SESSION_ID_PLACEHOLDER"
29- initiators : []
23+ action : add
24+ type : standalone
25+ engine : " ECMAScript : Graal.js"
26+ name : set-mcp-session-id
27+ inline : |
28+ org.zaproxy.zap.extension.script.ScriptVars.setGlobalVar('mcpSessionId', 'MCP_SESSION_ID_PLACEHOLDER')
29+
30+ - type : script
31+ parameters :
32+ action : run
33+ type : standalone
34+ name : set-mcp-session-id
35+
36+ # Load and enable the HTTP Sender script to add headers to all requests
37+ - type : script
38+ parameters :
39+ action : add
40+ type : httpsender
41+ engine : " Oracle Nashorn"
42+ name : add-mcp-session-header
43+ file : /opt/rapidast/work/scripts/zap/add-mcp-session-header.js
44+
45+ - type : script
46+ parameters :
47+ action : enable
48+ type : httpsender
49+ name : add-mcp-session-header
You can’t perform that action at this time.
0 commit comments