Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

HTTP Sender Script issue

48 views
Skip to first unread message

sonawan...@gmail.com

unread,
Feb 27, 2025, 2:17:24 AMFeb 27
to ZAP User Group
Hello Team

I am using this HTTP Sender script - for this script i am getting below error

function sendingRequest(msg, initiator, helper) {
    print("sendingRequest called");
}

function responseReceived(msg, initiator, helper) {
    print("responseReceived called");
}


my script location is "C:\Users\<myusername>\zap-scripts\api-interceptor.js"

2025-02-27 12:44:42,052 [AWT-EventQueue-0] ERROR UncaughtExceptionLogger - Exception in thread "AWT-EventQueue-0"
java.lang.NullPointerException: Cannot invoke "java.nio.file.Path.register(java.nio.file.WatchService, java.nio.file.WatchEvent$Kind[])" because the return value of "java.nio.file.Path.getParent()" is null
at org.zaproxy.zap.extension.scripts.ConsolePanel.setScript(ConsolePanel.java:621) ~[?:?]
at org.zaproxy.zap.extension.scripts.ExtensionScriptsUI.displayScript(ExtensionScriptsUI.java:460) ~[?:?]
at org.zaproxy.zap.extension.scripts.ScriptsListPanel.selectionChanged(ScriptsListPanel.java:604) ~[?:?]
at org.zaproxy.zap.extension.scripts.ScriptsListPanel.lambda$getTree$3(ScriptsListPanel.java:588) ~[?:?]
at java.desktop/javax.swing.JTree.fireValueChanged(JTree.java:3019) ~[?:?]
at java.desktop/javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3520) ~[?:?]
at java.desktop/javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:650) ~[?:?]
at java.desktop/javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1120) ~[?:?]
at java.desktop/javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:306) ~[?:?]
at java.desktop/javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:200) ~[?:?]
at java.desktop/javax.swing.JTree.setSelectionPath(JTree.java:1709) ~[?:?]
at java.desktop/javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2761) ~[?:?]
at java.desktop/javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:4096) ~[?:?]
at java.desktop/javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressedDND(BasicTreeUI.java:4073) ~[?:?]
at java.desktop/javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:4032) ~[?:?]
at java.desktop/javax.swing.plaf.basic.BasicTreeUI$MouseHandler.mousePressed(BasicTreeUI.java:3278) ~[?:?]
at com.formdev.flatlaf.ui.FlatTreeUI$1.mousePressed(FlatTreeUI.java:265) ~[flatlaf-3.5.4.jar:3.5.4]
at java.desktop/java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:287) ~[?:?]
at java.desktop/java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:287) ~[?:?]
at java.desktop/java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:287) ~[?:?]
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6618) ~[?:?]
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3398) ~[?:?]
at java.desktop/java.awt.Component.processEvent(Component.java:6386) ~[?:?]
at java.desktop/java.awt.Container.processEvent(Container.java:2266) ~[?:?]
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4996) ~[?:?]
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324) ~[?:?]
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828) ~[?:?]
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948) ~[?:?]
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4572) ~[?:?]
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516) ~[?:?]
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310) ~[?:?]
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780) ~[?:?]
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828) ~[?:?]
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775) ~[?:?]
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720) ~[?:?]
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714) ~[?:?]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) ~[?:?]
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) ~[?:?]
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98) ~[?:?]
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747) ~[?:?]
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745) ~[?:?]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) ~[?:?]
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) ~[?:?]
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744) ~[?:?]
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) [?:?]
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) [?:?]
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) [?:?]
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) [?:?]
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) [?:?]
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) [?:?]

sonawan...@gmail.com

unread,
Feb 27, 2025, 2:27:42 AMFeb 27
to ZAP User Group
To validate the path and access issues i tried below java script 

import java.nio.file.Path;
import java.nio.file.Paths;

public class TestFilePath {
    public static void main(String[] args) {
        Path path = Paths.get("C:\\Users\\ssonawane5\\zap-scripts\\api-interceptor.js");
        System.out.println("File Path: " + path);
        System.out.println("Parent Directory: " + path.getParent());
    }
}

and it worked 
& 'C:\Program Files\Java\jdk-21\bin\java.exe' '-XX:+ShowCodeDetailsInExceptionMessages' '-cp' 'C:\Users\ssonawane5\AppData\Local\Temp\vscodesws_9ec46\jdt_ws\jdt.ls-java-project\bin' 'TestFilePath'
File Path: C:\Users\ssonawane5\zap-scripts\api-interceptor.js
Parent Directory: C:\Users\ssonawane5\zap-scripts


which means there is no access issues to the script i believe 

sonawan...@gmail.com

unread,
Feb 27, 2025, 5:26:33 AMFeb 27
to ZAP User Group
Hello 

Observation 
now i tried to kept the script at - "C:\Users\ssonawane5\ZAP\scripts\scripts\httpsender\api-interceptor.js"
and tried to load using UI and i am seeing its working 

but when i try to load the same script using API - the script is throwing errors
localhost:8080/JSON/script/action/load/?apikey=cu8lc9vka187lc2llqnje9gkg8&scriptName=C%3A%5CUsers%5Cssonawane5%5CZAP%5Cscripts%5Cscripts%5Chttpsender%5Capi-interceptor.js&scriptType=httpsender&scriptEngine=Graal.js&fileName=interceptor_qp.js&scriptDescription=&charset=UTF-8

sonawan...@gmail.com

unread,
Feb 27, 2025, 5:35:21 AMFeb 27
to ZAP User Group
Correct API Call
I tried keeping this file at "C:\Program Files\ZAP\Zed Attack Proxy\api-interceptor.js" 

but issue is same - the same script is working when Loaded via UI but when loaded via API its not working 

Simon Bennetts

unread,
Mar 3, 2025, 7:52:26 AMMar 3
to ZAP User Group
Hiya,

Is there any more info in the zap.log file?

Cheers,

Simon

sonawan...@gmail.com

unread,
Mar 4, 2025, 12:46:38 PMMar 4
to ZAP User Group
Hello Simon

I cleaned the zap.log file to get the most accurate log
so now i have loaded + enabled the HTTP Internceptor script  using API also i have set the required global variable using the API



Surprisingly when i added the same script using the ZAP UI - the script is working just perfect - no errors in the logs - refer below image

(interestingly this Template option is missing in ZAP API call but its present in UI)


Screenshot 2025-03-04 231426.png

Simon Bennetts

unread,
Mar 5, 2025, 12:40:35 PMMar 5
to ZAP User Group
Strange :/

Try specifying the full path for the fileName.
That worked fine for me.
But when I specified an invalid path it gave me a "Does Not Exist" error so I'm not sure this will solve your problem.
Reply all
Reply to author
Forward
0 new messages