javascript

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package javascript - express.go provides Express.js framework input patterns

Package javascript - fastify.go provides Fastify framework input patterns

Package javascript - frameworks.go provides JavaScript framework pattern registry and universal patterns All JavaScript framework patterns should be registered here

Package javascript - koa.go provides Koa.js framework input patterns

Package javascript - nestjs.go provides NestJS framework input patterns

Package javascript provides centralized JavaScript patterns for semantic analysis

Index

Constants

This section is empty.

Variables

View Source
var (
	// InputMethodPattern matches method names that ALWAYS indicate user input
	// e.g., get, json, text, param, params, query, body, headers, cookies
	InputMethodPattern = regexp.MustCompile(`(?i)^(get|json|text|param|params|query|body|headers?|cookies?|all)$`)

	// InputPropertyPattern matches property names that typically hold user input
	// e.g., body, query, params, headers, cookies, value, search, hash
	InputPropertyPattern = regexp.MustCompile(`(?i)^(body|query|params?|headers?|cookies?|value|search|hash|href|response(Text|XML)?)$`)

	// InputObjectPattern matches object/variable names that suggest an input carrier
	// e.g., req, request, ctx, context, event
	InputObjectPattern = regexp.MustCompile(`(?i)^(req|request|ctx|context|event|xhr|params|searchParams)$`)

	// DOMSourcePattern matches DOM properties that are user-controllable
	DOMSourcePattern = regexp.MustCompile(`(?i)(location\.(search|hash|href)|document\.(cookie|URL|referrer)|\.value\b)`)

	// NetworkResponsePattern matches network response properties
	NetworkResponsePattern = regexp.MustCompile(`(?i)(response(Text|XML)?|\.json\(\)|\.text\(\))`)
)

Universal patterns for detecting input across ANY JavaScript framework

View Source
var (
	// MapGetPattern matches .get('key') or .get("key")
	// Used to extract keys from Map/object .get() calls
	MapGetPattern = regexp.MustCompile(`\.get\(['"](\w+)['"]\)`)

	// BracketPropertyPattern matches ['key'] or ["key"] at start of string
	// Used to extract property names from bracket notation
	BracketPropertyPattern = regexp.MustCompile(`^\[['"](\w+)['"]\]`)

	// DotPropertyPattern matches .property at start of string
	// Used to extract property names from dot notation
	DotPropertyPattern = regexp.MustCompile(`^\.(\w+)`)

	// ThisPropertyAssignPattern matches this.property = ...
	// Used to detect constructor parameter flow to properties
	ThisPropertyAssignPattern = regexp.MustCompile(`this\.(\w+)\s*=`)
)
View Source
var Definitions = getDefinitions("javascript")

Definitions contains the source definitions for JavaScript.

View Source
var InputMethodPatterns = []string{

	".get(",
	".getAll(",

	".json(",
	".text(",
	".formData(",
	".blob(",
	".arrayBuffer(",

	".get(",
	".getAll(",

	".readFile(",
	".readFileSync(",
	".read(",
	".readSync(",

	".question(",
}

InputMethodPatterns contains universal method call patterns These match .method() calls that return user input

View Source
var InputPropertyPatterns = []string{
	".body",
	".query",
	".params",
	".headers",
	".cookies",
	".value",
	".search",
	".hash",
	".href",
	".cookie",
	".referrer",
	".response",
	".responseText",
	".responseXML",
}

InputPropertyPatterns contains universal property access patterns These match .property access on input objects

View Source
var Registry = common.NewFrameworkPatternRegistry("javascript")

Registry is the global JavaScript framework pattern registry

View Source
var TypeScriptDefinitions = getDefinitions("typescript")

TypeScriptDefinitions contains the source definitions for TypeScript.

Functions

func BuildThisPropertyAssignPattern

func BuildThisPropertyAssignPattern(paramName string) *regexp.Regexp

BuildThisPropertyAssignPattern creates a pattern for this.property = ... paramName

func ExtractBracketKey

func ExtractBracketKey(expr string) string

ExtractBracketKey extracts the key from bracket notation ['key']

func ExtractDotProperty

func ExtractDotProperty(expr string) string

ExtractDotProperty extracts property name from .property notation

func ExtractMapKey

func ExtractMapKey(expr string) string

ExtractMapKey extracts the key from a .get('key') expression

func GetAllPatterns

func GetAllPatterns() []*common.FrameworkPattern

GetAllPatterns returns all registered framework patterns

func GetPatternByID

func GetPatternByID(id string) *common.FrameworkPattern

GetPatternByID returns a pattern by its ID

func GetPatternsByFramework

func GetPatternsByFramework(framework string) []*common.FrameworkPattern

GetPatternsByFramework returns patterns for a specific framework

func IsDOMSource

func IsDOMSource(expr string) bool

IsDOMSource checks if an expression accesses a DOM source

func IsInputMethod

func IsInputMethod(methodName string) bool

IsInputMethod checks if a method name always indicates user input

func IsInputMethodCall

func IsInputMethodCall(expr string) bool

IsInputMethodCall checks if an expression matches an input method pattern

func IsInputObject

func IsInputObject(objectName string) bool

IsInputObject checks if a variable/object name suggests an input carrier

func IsInputProperty

func IsInputProperty(propertyName string) bool

IsInputProperty checks if a property name typically holds user input

func IsInputPropertyAccess

func IsInputPropertyAccess(expr string) bool

IsInputPropertyAccess checks if an expression matches an input property pattern

func IsNetworkResponse

func IsNetworkResponse(expr string) bool

IsNetworkResponse checks if an expression accesses a network response

Types

type Matcher

type Matcher struct {
	*common.BaseMatcher
}

Matcher matches JavaScript user input sources

func NewMatcher

func NewMatcher() *Matcher

NewMatcher creates a new JavaScript source matcher

type TypeScriptMatcher

type TypeScriptMatcher struct {
	*common.BaseMatcher
}

TypeScriptMatcher matches TypeScript user input sources (same as JavaScript)

func NewTypeScriptMatcher

func NewTypeScriptMatcher() *TypeScriptMatcher

NewTypeScriptMatcher creates a new TypeScript source matcher

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL