mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 01:15:27 +00:00
Adding support for implicit validation during marshal/unmarshal (#1329)
This commit is contained in:
parent
fea3fabdf2
commit
1fbbce4e41
@ -3,7 +3,6 @@ module github.com/projectdiscovery/nuclei/v2
|
|||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Ice3man543/nvd v1.0.8
|
|
||||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
|
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible
|
||||||
github.com/alecthomas/jsonschema v0.0.0-20211022214203-8b29eab41725
|
github.com/alecthomas/jsonschema v0.0.0-20211022214203-8b29eab41725
|
||||||
github.com/andygrunwald/go-jira v1.14.0
|
github.com/andygrunwald/go-jira v1.14.0
|
||||||
@ -47,7 +46,6 @@ require (
|
|||||||
github.com/shirou/gopsutil/v3 v3.21.9
|
github.com/shirou/gopsutil/v3 v3.21.9
|
||||||
github.com/spaolacci/murmur3 v1.1.0
|
github.com/spaolacci/murmur3 v1.1.0
|
||||||
github.com/spf13/cast v1.4.1
|
github.com/spf13/cast v1.4.1
|
||||||
github.com/stretchr/testify v1.7.0
|
|
||||||
github.com/syndtr/goleveldb v1.0.0
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible
|
github.com/tj/go-update v2.2.5-0.20200519121640-62b4b798fd68+incompatible
|
||||||
github.com/valyala/fasttemplate v1.2.1
|
github.com/valyala/fasttemplate v1.2.1
|
||||||
@ -67,6 +65,11 @@ require (
|
|||||||
|
|
||||||
require github.com/projectdiscovery/folderutil v0.0.0-20211206150108-b4e7ea80f36e
|
require github.com/projectdiscovery/folderutil v0.0.0-20211206150108-b4e7ea80f36e
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Ice3man543/nvd v1.0.8
|
||||||
|
github.com/stretchr/testify v1.7.0
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.mills.io/prologic/smtpd v0.0.0-20210710122116-a525b76c287a // indirect
|
git.mills.io/prologic/smtpd v0.0.0-20210710122116-a525b76c287a // indirect
|
||||||
github.com/PuerkitoBio/goquery v1.6.0 // indirect
|
github.com/PuerkitoBio/goquery v1.6.0 // indirect
|
||||||
|
|||||||
@ -2,6 +2,9 @@
|
|||||||
package templates
|
package templates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
validate "github.com/go-playground/validator/v10"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
"github.com/projectdiscovery/nuclei/v2/pkg/model"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
||||||
@ -13,6 +16,8 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/websocket"
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/websocket"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
"github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/workflows"
|
"github.com/projectdiscovery/nuclei/v2/pkg/workflows"
|
||||||
|
"go.uber.org/multierr"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Template is a YAML input file which defines all the requests and
|
// Template is a YAML input file which defines all the requests and
|
||||||
@ -121,3 +126,41 @@ func (template *Template) Type() types.ProtocolType {
|
|||||||
return types.InvalidProtocol
|
return types.InvalidProtocol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalYAML forces recursive struct validation during marshal operation
|
||||||
|
func (template *Template) MarshalYAML() ([]byte, error) {
|
||||||
|
out, marshalErr := yaml.Marshal(template)
|
||||||
|
errValidate := validate.New().Struct(template)
|
||||||
|
return out, multierr.Append(marshalErr, errValidate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalYAML forces recursive struct validation after unmarshal operation
|
||||||
|
func (template *Template) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
type Alias Template
|
||||||
|
alias := &Alias{}
|
||||||
|
err := unmarshal(alias)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*template = Template(*alias)
|
||||||
|
return validate.New().Struct(template)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON forces recursive struct validation during marshal operation
|
||||||
|
func (template *Template) MarshalJSON() ([]byte, error) {
|
||||||
|
out, marshalErr := json.Marshal(template)
|
||||||
|
errValidate := validate.New().Struct(template)
|
||||||
|
return out, multierr.Append(marshalErr, errValidate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON forces recursive struct validation after unmarshal operation
|
||||||
|
func (template *Template) UnmarshalJSON(data []byte) error {
|
||||||
|
type Alias Template
|
||||||
|
alias := &Alias{}
|
||||||
|
err := json.Unmarshal(data, alias)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*template = Template(*alias)
|
||||||
|
return validate.New().Struct(template)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user