Added attachment validation

pull/1972/head
Glenn Wilkinson 2020-08-16 22:34:13 +01:00
parent 291f20dc03
commit af0a630ea3
2 changed files with 27 additions and 0 deletions

View File

@ -21,6 +21,27 @@ type Attachment struct {
vanillaFile bool // Vanilla file has no template variables
}
// ValidateAttachment ensures that the provided attachment uses the supported template variables correctly.
func (a Attachment) ValidateAttachment() error {
ptx := PhishingTemplateContext{
BaseRecipient: BaseRecipient{
FirstName: "Foo",
LastName: "Bar",
Email: "foo@bar.com",
},
BaseURL: "http://testurl.com",
URL: "http://testurl.com/?rid=1234567",
TrackingURL: "http://testurl.local/track?rid=1234567",
Tracker: "<img alt='' style='display: none' src='http://testurl.local/track?rid=1234567'/>",
From: "From Address",
RId: "1234567",
}
_, err := a.ApplyTemplate(ptx)
return err
}
// ApplyTemplate parses different attachment files and applies the supplied phishing template.
func (a *Attachment) ApplyTemplate(ptx PhishingTemplateContext) (io.Reader, error) {

View File

@ -40,6 +40,12 @@ func (t *Template) Validate() error {
if err := ValidateTemplate(t.Text); err != nil {
return err
}
for _, a := range t.Attachments {
if err := a.ValidateAttachment(); err != nil {
return err
}
}
return nil
}