-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added JSON format support for templates #3333
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CodFrm , I fixed a minor bug and added some missing tags along with a unit test .
currently Unit Test Fails because there is a marshal/unmarshal issue with enum types.
Problem/Reason
- In some enums ex:
severity
,signature
we useiota
andiota+1
for initialisation. this causes empty string to be marshalled and other similar issue causes due to inconsistency
$ go test -v ./... -run "TestTemplateStruct"
=== RUN TestTemplateStruct
templates_test.go:27:
Error Trace: /Users/tarun/reviews/nuclei/v2/pkg/templates/templates_test.go:27
Error: Expected nil, but got: invalid attack type:
Test: TestTemplateStruct
Messages: failed to unmarshal json template
--- FAIL: TestTemplateStruct (0.00s)
Note: |
@tarunKoyalwar while parsing json templates is ok func TestTemplateStruct(t *testing.T) {
bin := `{
"id": "valid-gmail-checker",
"info": {
"name": "Valid Google Mail Checker",
"author": "dievus,dwisiswant0",
"severity": "info",
"reference": [
"https://github.com/dievus/geeMailUserFinder"
]
},
"self-contained": true,
"requests": [
{
"method": "HEAD",
"path": [
"https://mail.google.com/mail/gxlu?email={{email}}"
],
"matchers": [
{
"type": "word",
"part": "header",
"words": [
"COMPASS"
]
}
]
}
]
}`
var jsonTemplate Template
err := json.Unmarshal([]byte(bin), &jsonTemplate)
require.Nil(t, err, "failed to unmarshal json template")
} |
Added the ability to judge an empty string when deserializing, and do nothing if it is empty s := strings.Trim(string(data), `"`)
if s == "" {
return nil
} |
@CodFrm , nice catch on the empty string deserialization issue , it seems like we almost have full support to JSON templates. currently it does not omit tags we are looking into a custom enum type so that will be fixed in near future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm !
@CodFrm by the way is there a specific usecase for this json support ? maybe we can add some helper functions in a followup issue/PR ?? |
@tarunKoyalwar We can implement a Network Catalog to read templates from remote servers and JSON is better for network transportation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - xxxTypeHolder
and iota
offset will be reworked and simplified in the future
Proposed changes
fix some json deserialization issues
Checklist