Hi Friends,
I am learning ZAP and have been trying for a while to get the authenticated user scan working for our Angular SPA. I tried going through the tutorials and articles and the user group discussions but so far it has not worked for me. So I am hoping that you would please help me get this user authenticated session in ZAP configured.
Most pages in our Single Page App have unique URLs/routes without using any parameters (i.e.
www.MyDomain.com/profile ;
www.MyDomain.com/UGC/Item1 ;
www.MyDomain.com/UGC/Item1/edit ) for each page. I mention this because we dont have pages where our SPA uses parameters for differentiating pages like in some of your examples (i.e. we don't have these kind of URLs --->
https://www.example.com/app/aaa?page=p1&ddd=eee OR
https://www.example.com/app/aaa?page=p2&ddd=fff ). BUT, there are cases when we open '
Modals' with FORM INPUT fields. These Modals don't really have their own unique URLs because they open as an overlay on the currently open page. Ideally we would like the ZAP scanner to scan/test all our pages along with all of their Modals.
First request: User login
Our Angular Frontend App in the client/browser receives the user's Login/Passwords in our Login form/page. Then the Fronend app Calls our REST API based BackEnd Application by inserting the Login/Password in a GET call like below :
In the RESPONSE to the above GET request, the response body looks like the JSON below:
{"access_token":"5ceb8q09c-2585-vsc8-b246-e33145cx746f","token_type":"bearer","refresh_token":"c2bref9-799s8-4ee0s-9dfc86-6dfes1b1b","expires_in":11999}
Subsequent Requests:
The Client FrontEnd app then sends the following GET request to get user info using the access_token it received in the first response above, and a cookie with userSessionId.
Connection: keep-alive
Authorization: Bearer 5ceb8q09c-2585-vsc8-b246-e33145cx746f
Cookie: userSessionId=c9631576-9bd5-4be3-a7ba-9e1f26c64a13
LOGOUT:
On ALL of our SPA pages, there is a Drop-Down-Menu in the header which has LOGOUT as the last item in the list. When the user clicks on Logout option, our FrontEnd app calls the 'api/logout' with a POST call as shown below...
REQUEST:
Connection: keep-alive
Authorization: Bearer 5ceb8q09c-2585-vsc8-b246-e33145cx746f
Cookie: userSessionId=c9631576-9bd5-4be3-a7ba-9e1f26c64a13
The RESPONSE to the above POST request is below:
{"statusCode":"200","statusMessage":"Operation Successful","responseBody":null}
At this point, the FrontEnd app deletes/clears the access_token from the client/browser's session storage and ROUTES USER to the login page.
Detecting Logged-In / Logged-Out state:
As you can see in the responses above, we do not really get the HTML for the page and so there is no 'Sign in' or 'Logout' text/indication that can be detected in the 'Response'. The only way to detect the logged in/out Status is to actually 'find' the 'Login' OR the 'SignOut' text on our Browser/client screen.
With the above explanation in mind, please address the following questions:
- How do we configure ZAP to run scans with automatically authenticated user sessions with oAuth tokens?
- How to make sure the AJAX-Scanner will scan the Modals?
- How to detect Logged in/out state by searching for some text in the screen instead of inspecting/expecting some text in the response?
- Would you be able to refer me to a similar example/sample configuration explained somewhere?
I am sorry this was long but I tried my best to provide enough details. I'd greatly appreciate if you could guide me in configuring ZAP to effectively scan our Angular SPA app.
Thank you.