Hello everyone, I'm trying to test an OpenAPI REST API from a bank app using OWASP ZAP. My goal is to mix manual testing and automate framework if possible.
I have 2 ways to export the API definition, using the openapi.yaml with swagger or using Postman collection directly. The problem comes with seting up the envinroment/context to be able to connect to the API, because i have to include the Authentication bearer token.
I tried several ways and always getting 400 as i can't or have not permission.
I tried using replacer to add the header (Following this steps):
Go to Tools > Options > Replacer.
Click Add to create a new replacement rule.
Configure the rule as follows:
- Description: Inject Bearer Token
- Enabled: ✅
- Match Type: Request Header
- Match String: Authorization
- Replacement String: Bearer YOUR_ACTUAL_TOKEN_HERE
- Match Regex: ❌ (unchecked)
- Initiators: Leave as default or select specific ones if needed.
Antoher way i tested is creating an
HTTP Sender Script in ZAP to inject the Authorization header dynamically and enable it forcing a new created user. This is the script:// Replace with your actual token
var token = "Bearer YOUR_ACTUAL_TOKEN_HERE";
function sendingRequest(msg, initiator, helper) {
msg.getRequestHeader().setHeader("Authorization", token);
}
function responseReceived(msg, initiator, helper) {
// No changes needed here
}
I have read in some posts to use env variables ZAP_AUTH_HEADER and ZAP_AUTH_HEADER_VALUE but the problem is the token expires in 10minutes and have to refresh manually every run.
Any tips, suggestions? I'm stuck here. I was able to test another api collections without the bearer token but not this one :(