pkg/js/CONTRIBUTE.md
The JS layer provides a mechanism to add scriptability into the Nuclei Engine. The pkg/js directory contains the implementation of the JS runtime in Nuclei. This document provides a guide to adding new libraries, extending existing ones and other types of contributions.
The Very First before making any type of contribution to javascript runtime in nuclei is taking a look at design.md to understand spread out design of nuclei javascript runtime.
Most of JavaScript API Reference documentation is auto-generated with help of code-generation and jsdocgen and hence any type of documentation contribution are always welcome and can be done by editing JavaScript jsdoc files
Improving existing libraries includes adding new functions, types, fixing bugs etc. to any of the existing libraries in libs directory. This is very easy to achieve and can be done by following steps below
Libraries/node_modules represent adding new protocol or something similar and should not include helper functions or types/objects .Adding new libraries requires few more steps than improving existing libraries and can be done by following steps below
Helper objects/types/functions can simply be understood as javascript utils to simplify writing javascript and reduce code duplication in javascript templates. Helper functions/objects are divided into two categories
javascript based helpers are written in javascript and are available in javascript runtime by default without needing to import any module. These are located in global/js directory and are exported using exports.js file.
go based helpers are written in go and can import any go library if required. Minimal/Simple helper functions can be directly added using runtime.Set("function_name", function) in global/scripts.go file. For more complex helpers, a new package can be created in libs directory and can be imported in global/scripts.go file. Refer to existing implementations in globals directory for more details.
JavaScript Protocol Documentation is auto-generated using [jsdoc] and is hosted at js-proto-docs. To update documentation, please follow steps mentioned at projectdiscovery/js-proto-docs
if !protocolstate.IsHostAllowed(host) {
// host is not valid according to network policy
return false, protocolstate.ErrHostDenied.Msgf(host)
}
(IsRDP, error) instead of returning multiple values (name, version string, err error). The second one will get converted to an array is much harder for consumers to deal with. Instead, try to return Structures which will be accessible natively.try/catch blocks and handle errors gracefully, showing useful information. By default, the implementation returns a Go error on an unhandled exception along with stack trace in debug mode.let/const instead of var to declare variables.