Send HTTP POST application/json using GraalJS

158 views
Skip to first unread message

Phùng Quang Trường

unread,
Aug 24, 2023, 7:00:40 AM8/24/23
to ZAP User Group
I'm trying to write GraalJS to send a POST application/json using GraalJS. I found some template inside ZAP but It is all about normal POST form. Also I know that JSON format is just text and I can send POST with text only but does anyone know how to send it in proper way or just send it as text?

psiinon

unread,
Aug 24, 2023, 7:10:55 AM8/24/23
to zaprox...@googlegroups.com

On Thu, Aug 24, 2023 at 1:00 PM Phùng Quang Trường <pqt12...@gmail.com> wrote:
I'm trying to write GraalJS to send a POST application/json using GraalJS. I found some template inside ZAP but It is all about normal POST form. Also I know that JSON format is just text and I can send POST with text only but does anyone know how to send it in proper way or just send it as text?

--
You received this message because you are subscribed to the Google Groups "ZAP User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zaproxy-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zaproxy-users/b6028f3c-9d96-4f0d-bd49-79d93758f8bfn%40googlegroups.com.


--
ZAP Project leader

Phùng Quang Trường

unread,
Aug 24, 2023, 7:51:40 AM8/24/23
to ZAP User Group
My application that I'm writing Authentication Script return both Set-Cookie header and API-Key in response body. I wonder if I can write Http Sender script to set Cookie header and API-key header that Active Scan can use to send request? 

psiinon

unread,
Aug 24, 2023, 7:53:43 AM8/24/23
to zaprox...@googlegroups.com
Have you tried the Authentication Tester?

If so, how far did it get?
If not .. then I recommend trying it :)

Cheers,

Simon



--
ZAP Project leader

Phùng Quang Trường

unread,
Aug 24, 2023, 7:58:51 AM8/24/23
to ZAP User Group
In fact, what I am trying to do is scan a list of API. Because of the application swagger doesn't have enough parameters. So I have to send my own request and import to ZAP using HAR. The problem is because this is API with out web interface so the Authentication Tester seem not to work with. The authentication method is a POST method with application/json. Return header Set-Cookie and API-Key.

psiinon

unread,
Aug 24, 2023, 9:28:22 AM8/24/23
to zaprox...@googlegroups.com
OK, that makes sence.
Yes, you can write an httpsender script to inject anything.
Make sure you read all of https://www.zaproxy.org/docs/authentication/ - that should help.

Also see https://www.zaproxy.org/blog/2023-02-01-authenticating-using-selenium/ - thats more complicated that your situation, but it might give you some idea of what you can do, eg with script variables.

Cheers,

Simon



--
ZAP Project leader

Phùng Quang Trường

unread,
Aug 24, 2023, 10:25:01 PM8/24/23
to ZAP User Group
One last question, if I write login script, do I still need to define Login/Logout regex to prevent the authentication script run every time?

psiinon

unread,
Aug 25, 2023, 3:10:18 AM8/25/23
to zaprox...@googlegroups.com
That depends.
You have 2 choices:
If you want ZAP to handle authentication then yes, you need to configure Logged in/out regexes :)

Cheers,

Simon



--
ZAP Project leader

Phùng Quang Trường

unread,
Aug 25, 2023, 4:31:28 AM8/25/23
to ZAP User Group

Got I, finally I can work with both Authentication Script and HttpSender. I wonder when I start Active Scan, does ZAP will run Authentication first or run Authentication Verification request first ?

psiinon

unread,
Aug 25, 2023, 4:33:24 AM8/25/23
to zaprox...@googlegroups.com
Your scripts should probably cope with both cases :)
But you can try it and see...



--
ZAP Project leader
Reply all
Reply to author
Forward
0 new messages