Path: blob/dev/pkg/fuzz/analyzers/xss/context.go
4538 views
// Package xss provides reflection context analysis for XSS detection1// in the nuclei fuzzing engine.2package xss34import "fmt"56// XSSContext represents where in an HTML document a reflected value appears.7type XSSContext int89const (10ContextUnknown XSSContext = iota // could not determine context11ContextHTMLBody // text content between tags12ContextHTMLAttribute // generic attribute value13ContextHTMLAttributeURL // URL attr (href, src, action, etc.)14ContextHTMLAttributeEvent // event handler attr (onclick, onerror, etc.)15ContextScript // executable <script> or javascript: URI16ContextScriptData // non-executable <script> (e.g. type="application/json")17ContextStyle // <style> block or style="" attribute18ContextComment // HTML comment19)2021// contextNames maps each XSSContext value to its human-readable name.22var contextNames = map[XSSContext]string{23ContextUnknown: "Unknown",24ContextHTMLBody: "HTMLBody",25ContextHTMLAttribute: "HTMLAttribute",26ContextHTMLAttributeURL: "HTMLAttributeURL",27ContextHTMLAttributeEvent: "HTMLAttributeEvent",28ContextScript: "Script",29ContextScriptData: "ScriptData",30ContextStyle: "Style",31ContextComment: "Comment",32}3334// String returns the name of the XSS context.35func (c XSSContext) String() string {36if name, ok := contextNames[c]; ok {37return name38}39return fmt.Sprintf("XSSContext(%d)", int(c))40}414243