Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/fuzz/analyzers/xss/context.go
4538 views
1
// Package xss provides reflection context analysis for XSS detection
2
// in the nuclei fuzzing engine.
3
package xss
4
5
import "fmt"
6
7
// XSSContext represents where in an HTML document a reflected value appears.
8
type XSSContext int
9
10
const (
11
ContextUnknown XSSContext = iota // could not determine context
12
ContextHTMLBody // text content between tags
13
ContextHTMLAttribute // generic attribute value
14
ContextHTMLAttributeURL // URL attr (href, src, action, etc.)
15
ContextHTMLAttributeEvent // event handler attr (onclick, onerror, etc.)
16
ContextScript // executable <script> or javascript: URI
17
ContextScriptData // non-executable <script> (e.g. type="application/json")
18
ContextStyle // <style> block or style="" attribute
19
ContextComment // HTML comment
20
)
21
22
// contextNames maps each XSSContext value to its human-readable name.
23
var contextNames = map[XSSContext]string{
24
ContextUnknown: "Unknown",
25
ContextHTMLBody: "HTMLBody",
26
ContextHTMLAttribute: "HTMLAttribute",
27
ContextHTMLAttributeURL: "HTMLAttributeURL",
28
ContextHTMLAttributeEvent: "HTMLAttributeEvent",
29
ContextScript: "Script",
30
ContextScriptData: "ScriptData",
31
ContextStyle: "Style",
32
ContextComment: "Comment",
33
}
34
35
// String returns the name of the XSS context.
36
func (c XSSContext) String() string {
37
if name, ok := contextNames[c]; ok {
38
return name
39
}
40
return fmt.Sprintf("XSSContext(%d)", int(c))
41
}
42
43