Template signing provides cryptographic verification for Nuclei templates, especially those using the code protocol. Digital signatures ensure template authenticity and prevent unauthorized modifications.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/projectdiscovery/nuclei/llms.txt
Use this file to discover all available pages before exploring further.
Why sign templates?
Template signing addresses critical security concerns:Code execution safety
Code protocol templates execute arbitrary code. Signatures verify trusted authorship.
Tamper detection
Detect any modifications to templates after signing
Author verification
Confirm template origin and chain of trust
Community trust
Build confidence in shared templates through cryptographic proof
When signatures are required
Examples requiring signatures:Signature mechanism
Nuclei uses ECDSA (Elliptic Curve Digital Signature Algorithm) with SHA-256 for template signing.Signature format
Signatures are appended to templates as comments:pkg/templates/signer/tmpl_signer.go:24-25):
- Signature: ECDSA signature encoded as hex
- User fragment: MD5 hash of public key for re-signing verification
Setting up signing
Generate signing keys
On first use, Nuclei generates a key pair automatically:Key generation internals
Frompkg/templates/signer/handler.go:132-170:
Certificates are self-signed and valid for 4 years. They use the P-256 elliptic curve.
Signing templates
Sign a template
Use the-sign flag to sign templates:
- Single template
- Multiple templates
- With custom keys
Sign a specific template:
Signing process
The signing process (frompkg/templates/template_sign.go:59-88):
File imports in signatures
When templates reference external files, their contents are included in the signature:The signing process loads referenced files and includes them in the signature calculation (see
pkg/templates/signer/tmpl_signer.go:98-106).Verifying signatures
Automatic verification
Nuclei automatically verifies template signatures during execution:Verification process
Frompkg/templates/signer/tmpl_signer.go:131-165:
Verification failures
Common verification failures:no signature found
no signature found
Cause: Code protocol template lacks signature.Solution: Sign the template:
signature must be at the end
signature must be at the end
Cause: Signature not in expected format or location.Solution: Ensure signature is the last line and starts with
# digest:.Template has been tampered
Template has been tampered
Cause: Content modified after signing.Solution: Re-sign the template after making changes.
Invalid passphrase
Invalid passphrase
Cause: Incorrect passphrase for encrypted private key.Solution: Enter the correct passphrase when prompted.
Re-signing templates
Re-signing restrictions
Frompkg/templates/signer/tmpl_signer.go:77-95:
User fragment
The user fragment identifies the signer using an MD5 hash of their public key:Custom certificate management
Environment variables
Override default certificate locations:Programmatic signing
Use the signing API programmatically:Certificate details
Frompkg/templates/signer/handler.go:23-30:
- Type: X.509 certificate
- Algorithm: ECDSA with SHA-256
- Curve: P-256 (secp256r1)
- Validity: 4 years from generation
- Subject: Common Name = User/Organization identifier
Security considerations
Private key protection
Template verification in workflows
Always verify signatures in production:.github/workflows/scan.yml
Testing signature functionality
Example test cases frompkg/templates/signer/tmpl_signer_test.go:36-90:
- Sign and verify
- Detect tampering
- Code protocol enforcement
Troubleshooting
Keys not found
Keys not found
Issue:
nuclei user certificate not foundSolution: Generate keys first:Passphrase prompt on every sign
Passphrase prompt on every sign
Issue: Private key is encrypted.Solution: Either enter passphrase each time or regenerate without passphrase.
Cannot sign workflow templates
Cannot sign workflow templates
Issue:
given filePath is not a templateSolution: Workflow templates (templates with workflows: section) cannot be signed. Only single protocol templates support signing.Re-signing fails with security error
Re-signing fails with security error
Issue:
re-signing code templates are not allowed for security reasonsSolution: You’re trying to re-sign a code template originally signed by someone else. Only the original signer can re-sign code templates.Advanced usage
Skip key generation
For CI/CD environments where keys should be pre-configured:Allow local file access
For signing templates that reference local files:Best practices
✓ Always sign code protocol templates before distribution✓ Protect private keys with passphrases✓ Store keys securely, never in version control✓ Verify signatures in production environments✓ Use environment variables for custom certificate paths✓ Test signed templates thoroughly before sharing✓ Document signing requirements for contributors✓ Backup keys in secure, encrypted storage
Next steps
Contributing templates
Learn how to contribute signed templates
Code protocol
Understand code protocol templates
Best practices
Follow template development guidelines
Validation
Validate templates before signing