Why flow control
Flow control solves two major limitations of traditional templates:- Conditional execution - Execute requests only when certain conditions are met
- Request orchestration - Control execution order, iterate over values, and implement custom logic
Flow uses Goja as the JavaScript runtime engine (ECMAScript 5.1 compatible).
Basic flow syntax
Add aflow field to your template with JavaScript code:
- Simple
- Multi-line
Protocol execution functions
Flow provides functions to execute protocol requests:Execute all HTTP requests.
Execute specific HTTP request by ID or index.
Execute DNS requests.
Execute SSL/TLS requests.
Execute network/TCP requests.
Template context functions
Create or update a variable in template context.
Get a value from template context (extracted values, variables).
Helper functions
Safely iterate over any value type (arrays, objects, strings, numbers), handling null/empty values.
Print message to stdout (for debugging).
Conditional execution
Execute requests only when conditions are met:Request orchestration
Iterate over extracted values and execute requests for each:Advanced patterns
VHost enumeration
Multi-protocol value sharing
Flow vs workflows
- Flow
- Workflows
Advantages:
- Single template file
- Full JavaScript control
- Iterate over extracted values
- Custom conditional logic
- Access to all JavaScript features
- Complex multi-step templates
- Dynamic iteration
- Custom orchestration logic
- Templates with data processing
JavaScript features
Flow supports ECMAScript 5.1, including:- Variables:
let,var,const - Control flow:
if,else,for,while,switch - Functions:
function() {}, anonymous functions - Arrays:
[],.push(),.pop(),.length - Objects:
{}, property access - Operators:
&&,||,!,==,===,>,< - String manipulation:
.replace(),.substring(),.indexOf()
Using DSL functions in flow
You can use Nuclei DSL helper functions in flow:Debugging flows
Use thelog() function for debugging:
Real-world examples
Best practices
- Use internal matchers - Hide intermediate checks with
internal: true - Extract only needed data - Use
internal: trueon extractors used in flow - Validate extracted values - Check if values exist before using them
- Log for debugging - Use
log()during development - Handle errors gracefully - Use conditional checks before executing requests
- Keep flow logic simple - Complex logic can be hard to debug
- Document flow logic - Add comments explaining the orchestration
- Test thoroughly - Verify all execution paths work as expected
Common patterns
Conditional chaining
Loop with condition
Retry logic
Multiple protocol orchestration
Related
Workflows
Multi-template workflows
Variables
Template context
Extractors
Extract dynamic values
Helper Functions
DSL functions