### Run basic URL extraction example Source: https://pkg.go.dev/github.com/BishopFox/jsluice Command to execute the basic URL extraction example. ```bash ▶ go run examples/basic/main.go ``` -------------------------------- ### Run custom URL matcher example Source: https://pkg.go.dev/github.com/BishopFox/jsluice Command to execute the custom URL matcher example. ```bash ▶ go run examples/urlmatcher/main.go mailto:contact@example.com https://example.com ``` -------------------------------- ### Install jsluice command-line tool Source: https://pkg.go.dev/github.com/BishopFox/jsluice Use this command to install the jsluice CLI tool via Go. ```bash ▶ go install github.com/BishopFox/jsluice/cmd/jsluice@latest ``` -------------------------------- ### Run jsluice command examples Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Common usage patterns for extracting URLs, running tree-sitter queries, and finding secrets. ```bash jsluice urls -C 'auth=true; user=admin;' -H 'Specific-Header-One: true' -H 'Specific-Header-Two: false' local_file.js https://remote.host/example.js ``` ```bash jsluice query -q '(object) @m' one.js two.js ``` ```bash find . -name *.js' | jsluice secrets -c 5 --patterns=apikeys.json ``` -------------------------------- ### Example Secret Extraction Output Source: https://pkg.go.dev/github.com/BishopFox/jsluice This is an example of the JSON output produced when extracting secrets using the jsluice library with a custom matcher. It shows the identified secret's kind, data, severity, and contextual information. ```json { "kind": "fakeApi", "data": { "key": "apiKey", "value": "AUTH_1a2b3c4d5e6f" }, "severity": "low", "context": { "apiKey": "AUTH_1a2b3c4d5e6f", "apiURL": "https://api.example.com/v2/" } } ``` -------------------------------- ### Process WARC Files with jsluice Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice When the '--warc' flag is used, jsluice treats input files as WARC archives. This example demonstrates extracting information from a WARC file, likely containing web crawl data. ```bash ▶ jsluice urls --warc example.warc.gz | jq { "url": "/blog/admin.php?redirect=/login", "queryParams": [ "redirect" ], "bodyParams": [], "method": "GET", "type": "location.replace", "filename": "https://example.com/blog/" } ``` -------------------------------- ### Process Remote URLs with jsluice Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice jsluice can fetch and process JavaScript files directly from HTTP or HTTPS URLs. This example shows processing local and remote files, outputting structured data with 'jq'. ```bash ▶ jsluice urls demo.js https://example.com/jquery.js | jq { "url": "/api/users?id=EXPR&format=json", "queryParams": ["id", "format"], "method": "GET", "headers": { "X-Env": "stage" }, "type": "fetch" } { "url": "/api/v1/posts", "queryParams": [], "bodyParams": [ "postId" ], "method": "PUT", "headers": { "Content-Type": "application/json", "x-backend": "prod" }, "type": "$.ajax", "filename": "jquery.js" } ``` -------------------------------- ### JavaScript string concatenation example Source: https://pkg.go.dev/github.com/BishopFox/jsluice Example of JavaScript code where jsluice replaces unknown expressions with EXPR. ```javascript document.location = "/login?redirect=" + redirect + "&method=oauth" ``` -------------------------------- ### Create New Node Source: https://pkg.go.dev/github.com/BishopFox/jsluice Initializes a Node with a tree-sitter node and the full source code. ```go func NewNode(n *sitter.Node, source []byte) *Node ``` -------------------------------- ### Create a New Analyzer Instance Source: https://pkg.go.dev/github.com/BishopFox/jsluice NewAnalyzer initializes and returns a new Analyzer instance. It takes the JavaScript source code as a byte slice and prepares it for analysis. ```go func NewAnalyzer(source []byte) *Analyzer ``` -------------------------------- ### View jsluice help output Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Displays the help menu for the jsluice CLI, detailing available modes and global options. ```bash jsluice --help ``` -------------------------------- ### Execute Tree-sitter Queries Source: https://pkg.go.dev/github.com/BishopFox/jsluice Performs queries on the JavaScript AST. QueryMulti provides captured nodes grouped by match. ```go func (a *Analyzer) Query(q string, fn func(*Node)) ``` ```go func (a *Analyzer) QueryMulti(q string, fn func(QueryResult)) ``` -------------------------------- ### Compare jsluice with grep Source: https://pkg.go.dev/github.com/BishopFox/jsluice Demonstrates the limitations of using regular expressions for URL extraction compared to jsluice. ```bash ▶ JS='document.location = "/login?redirect=" + redirect + "&method=oauth"' ▶ echo $JS | grep -oE 'document\.location = "[^"]+"' document.location = "/login?redirect=" ``` -------------------------------- ### Print JavaScript Syntax Tree Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Generate a textual representation of the syntax tree for a JavaScript file. ```javascript console.log("Hello, world!") ``` ```bash ▶ jsluice tree hello.js hello.js: program expression_statement call_expression function: member_expression object: identifier (console) property: property_identifier (log) arguments: arguments string ("Hello, world!") ``` -------------------------------- ### Add jsluice package to project Source: https://pkg.go.dev/github.com/BishopFox/jsluice Use this command to add the jsluice package as a dependency to your Go project. ```bash ▶ go get github.com/BishopFox/jsluice ``` -------------------------------- ### Collapse URL Expressions Source: https://pkg.go.dev/github.com/BishopFox/jsluice Simplifies complex URL strings by replacing dynamic expressions with placeholders. ```go func (n *Node) CollapsedString() string ``` ```javascript './upload.php?profile='+res.id+'&show='+$('.participate_modal_container').attr('data-val') ``` ```text ./upload.php?profile=EXPR&show=EXPR ``` -------------------------------- ### ParseRegex - UserPattern Method Source: https://pkg.go.dev/github.com/BishopFox/jsluice ParseRegex compiles all user-defined regular expressions for a UserPattern into Go's regexp.Regexp types. This should be called before using the pattern for matching. ```go func (u *UserPattern) ParseRegex() error ``` -------------------------------- ### Extract URLs from JavaScript Source: https://pkg.go.dev/github.com/BishopFox/jsluice Demonstrates using the Analyzer to extract URLs from a JavaScript string. ```go analyzer := jsluice.NewAnalyzer([]byte(` const login = (redirect) => { document.location = "/login?redirect=" + redirect + "&method=oauth" } `)) for _, url := range analyzer.GetURLs() { j, err := json.MarshalIndent(url, "", " ") if err != nil { continue } fmt.Printf("%s\n", j) } ``` -------------------------------- ### Manage URL Matchers Source: https://pkg.go.dev/github.com/BishopFox/jsluice Adds custom URL matchers or disables the default set to restrict matching to user-defined logic. ```go func (a *Analyzer) AddURLMatcher(u URLMatcher) ``` ```go func (a *Analyzer) DisableDefaultURLMatchers() ``` -------------------------------- ### Node Structure Definition Source: https://pkg.go.dev/github.com/BishopFox/jsluice The internal wrapper for tree-sitter nodes. ```go type Node struct { // contains filtered or unexported fields } ``` -------------------------------- ### Node Traversal and Metadata Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods for accessing node children, capture names, and metadata. ```go func (n *Node) CaptureName() string ``` ```go func (n *Node) Child(index int) *Node ``` ```go func (n *Node) ChildByFieldName(name string) *Node ``` ```go func (n *Node) ChildCount() int ``` ```go func (n *Node) Children() []*Node ``` -------------------------------- ### Node Methods Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods for interacting with and transforming tree-sitter nodes. ```APIDOC ## AsGoType ### Description Returns a representation of a Node as a native Go type. ### Response #### Success Response (200) - **any** - Returns string, int, float64, map[string]any, []any, bool, or nil based on the node type. ## ChildByFieldName ### Description Fetches a child Node from a named field. ### Parameters #### Query Parameters - **name** (string) - Required - The name of the field to fetch. ## CollapsedString ### Description Attempts to simplify a node representing a URL into a more parseable format by replacing dynamic expressions with placeholders. ``` -------------------------------- ### Extract Objects with jsluice Query and jq Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Run a Tree-sitter query to extract JavaScript objects and pipe the output to 'jq' for pretty-printing. This demonstrates jsluice's ability to output valid JSONL for structured data. ```bash ▶ jsluice query -q '(object) @match' config.js | jq { "dns": [ "1.1.1.1", "8.8.8.8" ], "paths": { "blog": "/blog", "home": "/" }, "server": "example.com", "stage": false, "ttl": 3600 } { "blog": "/blog", "home": "/" } ``` -------------------------------- ### Run Custom Secret Matchers Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Execute jsluice secrets with a custom patterns file. ```javascript function getConfig(){ let config = { randomStr: "abc123xyz256", secret: "I quite like PHP", } return "eyJsb2wiOiAic29tZSBKU09OISIsICJjb3VudCI6IDEyM30K" } ``` ```bash ▶ jsluice secrets -p patterns.json simple-b64.js | jq { "kind": "base64", "data": { "match": "eyJsb2wiOiAic29tZSBKU09OISIsICJjb3VudCI6IDEyM30K" }, "filename": "simple-b64.js", "severity": "low", "context": null } { "kind": "genericSecret", "data": { "key": "secret", "value": "I quite like PHP" }, "filename": "simple-b64.js", "severity": "info", "context": { "randomStr": "abc123xyz256", "secret": "I quite like PHP" } } ``` ```text [%a-zA-Z0-9+/]+ ``` ```text ^[%a-zA-Z0-9+/]+$ ``` -------------------------------- ### SecretMatcher - UserPattern Method Source: https://pkg.go.dev/github.com/BishopFox/jsluice SecretMatcher returns a SecretMatcher instance derived from the UserPattern. This is useful for integrating custom patterns with the Analyzer's secret matching capabilities. ```go func (u *UserPattern) SecretMatcher() SecretMatcher ``` -------------------------------- ### Define custom URL matchers Source: https://pkg.go.dev/github.com/BishopFox/jsluice Use AddURLMatcher to define custom logic for identifying URLs in specific node types. ```go analyzer := jsluice.NewAnalyzer([]byte(` var fn = () => { var meta = { contact: "mailto:contact@example.com", home: "https://example.com" } return meta } `)) analyzer.AddURLMatcher( // The first value in the jsluice.URLMatcher struct is the type of node to look for. // It can be one of "string", "assignment_expression", or "call_expression" jsluice.URLMatcher{"string", func(n *jsluice.Node) *jsluice.URL { val := n.DecodedString() if !strings.HasPrefix(val, "mailto:") { return nil } return &jsluice.URL{ URL: val, Type: "mailto", } }}, ) for _, match := range analyzer.GetURLs() { fmt.Println(match.URL) } ``` -------------------------------- ### Convert Node to Go Types Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods to convert AST nodes into native Go types or internal representations. ```go func (n *Node) AsArray() []any ``` ```go func (n *Node) AsGoType() any ``` ```go func (n *Node) AsMap() map[string]any ``` ```go func (n *Node) AsNumber() any ``` ```go func (n *Node) AsObject() Object ``` ```text string => string number => int, float64 object => map[string]any array => []any false => false true => true null => nil other => string ``` -------------------------------- ### Node Navigation Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods for navigating the tree structure relative to a specific node. ```APIDOC ## Node Navigation Methods ### ForEachChild Iterates over a node's children in a depth-first manner. ### ForEachNamedChild Iterates over a node's named children in a depth-first manner. ### NamedChild Returns the 'named' child Node at the provided index. ### NamedChildren Returns a slice of *Node containing all named children for a node. ### Parent Returns the Parent Node for a Node. ### NextSibling / PrevSibling Returns the next or previous sibling in the tree. ``` -------------------------------- ### Object Methods Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods for interacting with JavaScript objects within JSLuice. ```APIDOC ## Object.GetNodeFunc ### Description GetNodeFunc is a general-purpose method for finding object properties by their key. The provided function is called with each key in turn. The first time that function returns true the corresponding *Node for that key is returned. ### Method func (o Object) GetNodeFunc(fn func(key string) bool) *Node ### Endpoint N/A (Method on Object type) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) * **Node** (*Node) - The node corresponding to the key for which the function returned true. #### Response Example None ``` ```APIDOC ## Object.GetNodeI ### Description GetNodeI is like GetNode, but case-insensitive. ### Method func (o Object) GetNodeI(key string) *Node ### Endpoint N/A (Method on Object type) ### Parameters #### Path Parameters None #### Query Parameters - **key** (string) - Required - The key to search for. #### Request Body None ### Request Example None ### Response #### Success Response (200) * **Node** (*Node) - The node corresponding to the key, case-insensitively. #### Response Example None ``` ```APIDOC ## Object.GetObject ### Description GetObject returns the property corresponding to the provided key as an Object. ### Method func (o Object) GetObject(key string) Object ### Endpoint N/A (Method on Object type) ### Parameters #### Path Parameters None #### Query Parameters - **key** (string) - Required - The key of the property to retrieve. #### Request Body None ### Request Example None ### Response #### Success Response (200) * **Object** (Object) - The property value as an Object. #### Response Example None ``` ```APIDOC ## Object.GetString ### Description GetString returns the property corresponding to the provided key as a string, or the defaultVal if the key is not found. ### Method func (o Object) GetString(key, defaultVal string) string ### Endpoint N/A (Method on Object type) ### Parameters #### Path Parameters None #### Query Parameters - **key** (string) - Required - The key of the property to retrieve. - **defaultVal** (string) - Required - The default value to return if the key is not found. #### Request Body None ### Request Example None ### Response #### Success Response (200) * **string** (string) - The property value as a string, or the default value. #### Response Example None ``` ```APIDOC ## Object.GetStringI ### Description GetStringI is like GetString, but the key is case-insensitive. ### Method func (o Object) GetStringI(key, defaultVal string) string ### Endpoint N/A (Method on Object type) ### Parameters #### Path Parameters None #### Query Parameters - **key** (string) - Required - The key of the property to retrieve, case-insensitively. - **defaultVal** (string) - Required - The default value to return if the key is not found. #### Request Body None ### Request Example None ### Response #### Success Response (200) * **string** (string) - The property value as a string, or the default value. #### Response Example None ``` ```APIDOC ## Object.HasValidNode ### Description HasValidNode returns true if the underlying node is a valid JavaScript object. ### Method func (o Object) HasValidNode() bool ### Endpoint N/A (Method on Object type) ### Parameters None ### Request Example None ### Response #### Success Response (200) * **bool** (bool) - True if the node is a valid JavaScript object, false otherwise. #### Response Example None ``` -------------------------------- ### Analyzer Methods Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods for configuring the Analyzer and extracting data from JavaScript source code. ```APIDOC ## AddSecretMatcher ### Description Adds a custom SecretMatcher to the Analyzer. ### Parameters #### Request Body - **s** (SecretMatcher) - Required - The secret matcher to add. ## AddSecretMatchers ### Description Adds multiple custom SecretMatchers to the Analyzer. ### Parameters #### Request Body - **ss** ([]SecretMatcher) - Required - A slice of secret matchers to add. ## AddURLMatcher ### Description Adds a custom URLMatcher to the Analyzer. ### Parameters #### Request Body - **u** (URLMatcher) - Required - The URL matcher to add. ## DisableDefaultURLMatchers ### Description Disables the default URLMatchers, ensuring only user-added URLMatchers are utilized. ## GetSecrets ### Description Uses the parse tree and configured Matchers to find secrets in JavaScript source code. ### Response #### Success Response (200) - **[]*Secret** - A slice of found secrets. ## GetURLs ### Description Searches the JavaScript source code for absolute and relative URLs. ### Response #### Success Response (200) - **[]*URL** - A slice of found URLs. ## Query ### Description Performs a tree-sitter query on the JavaScript being analyzed. The provided function is called for every node captured by the query. ### Parameters #### Request Body - **q** (string) - Required - The tree-sitter query string. - **fn** (func(*Node)) - Required - Callback function for each captured node. ## QueryMulti ### Description Performs a tree-sitter query on the JavaScript being analyzed, grouping captured nodes into a QueryResult. ### Parameters #### Request Body - **q** (string) - Required - The tree-sitter query string. - **fn** (func(QueryResult)) - Required - Callback function for each query match. ``` -------------------------------- ### UserPatterns Type and Methods Source: https://pkg.go.dev/github.com/BishopFox/jsluice Details on the UserPatterns type, which is a slice of UserPattern, and its associated methods. ```APIDOC ## UserPatterns ### Description UserPatterns is an alias for a slice of *UserPattern. ### Type Definition ```go type UserPatterns []*UserPattern ``` ## UserPatterns.SecretMatchers ### Description SecretMatchers returns a slice of SecretMatcher for use with (*Analyzer).AddSecretMatchers(). ### Method (UserPatterns) SecretMatchers ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response ([]SecretMatcher) - **[]SecretMatcher** ([]SecretMatcher) - A slice of SecretMatcher instances. #### Response Example ```json { "example": [ "", "" ] } ``` ``` -------------------------------- ### UserPattern Methods Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods associated with the UserPattern type for matching values and parsing regular expressions. ```APIDOC ## UserPattern.MatchValue ### Description MatchValue returns true if a pattern's value regex matches the supplied value, or if there is no value regex. ### Method (*UserPattern) MatchValue ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (bool) - **bool** (bool) - True if the value matches the pattern's regex, false otherwise. #### Response Example ```json { "example": true } ``` ## UserPattern.ParseRegex ### Description ParseRegex parses all of the user-provided regular expressions for a pattern into Go *regexp.Regexp types. ### Method (*UserPattern) ParseRegex ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (error) - **error** (error) - An error if parsing fails, otherwise nil. #### Response Example ```json { "example": null } ``` ## UserPattern.SecretMatcher ### Description SecretMatcher returns a SecretMatcher based on the UserPattern, for use with (*Analyzer).AddSecretMatcher(). ### Method (*UserPattern) SecretMatcher ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (SecretMatcher) - **SecretMatcher** (SecretMatcher) - A SecretMatcher instance. #### Response Example ```json { "example": "" } ``` ``` -------------------------------- ### Format JavaScript Code with jsluice Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Use the 'format' mode to reformat minified or unformatted JavaScript source code using the jsbeautifier-go library. This is useful for improving code readability. ```bash ▶ cat testdata/location.min.js function goToLogin(){location.href="/login/"+document.location.hash.substring(1)} let logout=()=>{document.location.replace("/logout")} ▶ jsluice format testdata/location.min.js function goToLogin() { location.href = "/login/" + document.location.hash.substring(1) } let logout = () => { document.location.replace("/logout") } ``` -------------------------------- ### Include Source Code in URL Extraction Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Use the -S flag to include the original source code snippet in the output when extracting URLs. ```bash ▶ jsluice urls location.js -I -S | jq { "url": "../../guestbook.html", "queryParams": [], "bodyParams": [], "method": "GET", "type": "locationAssignment", "source": "document.location = '../../guestbook.html'", "filename": "testdata/relative-location.js" } ``` -------------------------------- ### Resolve Relative Paths with Base URL Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Resolve relative paths to absolute URLs by providing a base URL with the -R or --resolve-paths flag. This is useful when analyzing paths in contexts where a base domain is known. ```javascript document.location = '../../guestbook.html' ``` ```bash ▶ cat location.js document.location = '../../guestbook.html' ▶ jsluice urls location.js -I -R https://example.com/~tom/photos/2003/ | jq { "url": "https://example.com/~tom/guestbook.html", "queryParams": [], "bodyParams": [], "method": "GET", "type": "locationAssignment", "filename": "location.js" } ``` -------------------------------- ### Define Custom Secret Matcher in Go Source: https://pkg.go.dev/github.com/BishopFox/jsluice Use this Go code to define a custom matcher for extracting secrets from JavaScript. It requires initializing a jsluice analyzer with the JavaScript source and then adding a SecretMatcher with a tree-sitter query and a callback function to identify and format secrets. ```go analyzer := jsluice.NewAnalyzer([]byte(` var config = { apiKey: "AUTH_1a2b3c4d5e6f", apiURL: "https://api.example.com/v2/" } `)) analyzer.AddSecretMatcher( jsluice.SecretMatcher{" (pair) @match", func(n *jsluice.Node) *jsluice.Secret { key := n.ChildByFieldName("key").DecodedString() value := n.ChildByFieldName("value").DecodedString() if !strings.Contains(key, "api") { return nil } if !strings.HasPrefix(value, "AUTH_") { return nil } return &jsluice.Secret{ Kind: "fakeApi", Data: map[string]string{ "key": key, "value": value, }, Severity: jsluice.SeverityLow, Context: n.Parent().AsMap(), } }}, ) for _, match := range analyzer.GetSecrets() { j, err := json.MarshalIndent(match, "", " ") if err != nil { continue } fmt.Printf("%s\n", j) } ``` -------------------------------- ### UserPattern Type and Methods Source: https://pkg.go.dev/github.com/BishopFox/jsluice Defines the UserPattern type for representing user-defined patterns and a method to match keys. ```APIDOC ## UserPattern Type ### Description A UserPattern represents a pattern that was provided by a when using the command-line tool. When using the package directly, a SecretMatcher can be created directly instead of creating a UserPattern. ### Type Definition type UserPattern struct { Name string `json:"name"` Key string `json:"key"` Value string `json:"value"` Severity Severity `json:"severity"` Object []*UserPattern `json:"object"` // contains filtered or unexported fields } ``` ```APIDOC ## UserPattern.MatchKey ### Description MatchKey returns true if a pattern's key regex matches the supplied value, or if there is no key regex. ### Method func (u *UserPattern) MatchKey(in string) bool ### Endpoint N/A (Method on UserPattern type) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **in** (string) - Required - The value to match against the pattern's key. ### Request Example None ### Response #### Success Response (200) * **bool** (bool) - True if the key matches, false otherwise. #### Response Example None ``` -------------------------------- ### Node Traversal and Inspection Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods for inspecting node properties, content, and navigating the syntax tree. ```APIDOC ## Node Methods ### Content Returns the source code for a particular node. ### DecodedString Returns a fully decoded version of a JavaScript string. ### IsNamed Returns true if the underlying node is named. ### IsStringy Returns true if a Node is a string or an expression starting with a string. ### IsValid Returns true if the *Node and the underlying tree-sitter node are both not nil. ### Type Returns the tree-sitter type string for a Node (e.g., string, object, call_expression). ``` -------------------------------- ### Define Custom Secret Matchers Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Supply a JSON file with regex patterns to define custom secret extraction rules. ```json [ { "name": "base64", "value": "(eyJ|YTo|Tzo|PD[89]|rO0)[%a-zA-Z0-9+/]+={0,2}", "severity": "low" }, { "name": "genericSecret", "key": "(secret|private|key)", "value": "[%a-zA-Z0-9+/]+" }, { "name": "firebaseConfig", "severity": "high", "object": [ {"key": "apiKey", "value": "^AIza.+"}, {"key": "authDomain"}, {"key": "projectId"}, {"key": "storageBucket"} ] } ] ``` -------------------------------- ### SecretMatchers - UserPatterns Method Source: https://pkg.go.dev/github.com/BishopFox/jsluice SecretMatchers generates a slice of SecretMatcher from a UserPatterns collection. This is intended for use with the (*Analyzer).AddSecretMatchers() method. ```go func (u UserPatterns) SecretMatchers() []SecretMatcher ``` -------------------------------- ### MatchValue - UserPattern Method Source: https://pkg.go.dev/github.com/BishopFox/jsluice Use MatchValue to check if a pattern's regex matches a given string. It returns true if there's a match or if no value regex is defined for the pattern. ```go func (u *UserPattern) MatchValue(in string) bool ``` -------------------------------- ### Extract URLs from JavaScript Files Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Use the 'urls' mode to extract URLs and paths from JavaScript files. This mode can identify URLs in assignments, function calls, and string literals. Output is in JSONL format. ```javascript fetch('/api/users?id=' + userId + '&format=json', { method: "GET", headers: { "X-Env": "stage" } }) ``` ```bash ▶ jsluice urls demo.js | jq { "url": "/api/users?id=EXPR&format=json", "queryParams": ["id", "format"], "method": "GET", "headers": { "X-Env": "stage" }, "type": "fetch" } ``` ```javascript $.ajax({ method: "PUT", url: "/api/v1/posts", data:{ postId: 324 }, headers: { "Content-Type": "application/json", "x-backend": "prod" }}, function(data, status){ location.href = data.redirect; } ) ``` ```bash ▶ jsluice urls jquery.js | jq { "url": "/api/v1/posts", "queryParams": [], "bodyParams": [ "postId" ], "method": "PUT", "headers": { "Content-Type": "application/json", "x-backend": "prod" }, "type": "$.ajax", "filename": "jquery.js" } ``` -------------------------------- ### ParseUserPatterns Function Source: https://pkg.go.dev/github.com/BishopFox/jsluice ParseUserPatterns reads a JSON file from an io.Reader that defines user patterns. It returns a UserPatterns slice and any error encountered during parsing. ```go func ParseUserPatterns(r io.Reader) (UserPatterns, error) ``` -------------------------------- ### Add Custom Secret Matchers Source: https://pkg.go.dev/github.com/BishopFox/jsluice Registers one or more custom SecretMatcher implementations to the Analyzer. ```go func (a *Analyzer) AddSecretMatcher(s SecretMatcher) ``` ```go func (a *Analyzer) AddSecretMatchers(ss []SecretMatcher) ``` -------------------------------- ### Print JavaScript Syntax Tree Source: https://pkg.go.dev/github.com/BishopFox/jsluice PrintTree generates a string representation of the syntax tree for given JavaScript source code. This is helpful for debugging and understanding code structure. ```go func PrintTree(source []byte) string ``` -------------------------------- ### Extract Secrets and URLs Source: https://pkg.go.dev/github.com/BishopFox/jsluice Retrieves identified secrets or URLs from the parsed JavaScript source. ```go func (a *Analyzer) GetSecrets() []*Secret ``` ```go func (a *Analyzer) GetURLs() []*URL ``` -------------------------------- ### Utility Functions Source: https://pkg.go.dev/github.com/BishopFox/jsluice Utility functions for decoding JavaScript strings and analyzing source code structure. ```APIDOC ## DecodeString ### Description Converts JavaScript escape sequences (hex, unicode, octal, single character) in a raw string into their decoded representation. ### Parameters - **in** (string) - Required - The raw string containing escape sequences. ### Response - **string** - The decoded string. ## MaybeURL ### Description Determines if a given string is likely a URL. ### Parameters - **in** (string) - Required - The string to evaluate. ### Response - **bool** - True if the string is likely a URL. ## PrintTree ### Description Returns a string representation of the syntax tree for the provided JavaScript source. ### Parameters - **source** ([]byte) - Required - The JavaScript source code. ### Response - **string** - The syntax tree representation. ``` -------------------------------- ### Extract String Literals with jsluice Query Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Use the 'query' mode to extract all string literals from JavaScript files using Tree-sitter queries. The '@str' part of the query specifies the capture group to extract. ```javascript const config = { stage: false, server: "example.com", ttl: 3600, dns: ["1.1.1.1", "8.8.8.8"], paths: { "home": "/", "blog": "/blog" } } ``` ```bash ▶ jsluice query -q '(string) @str' config.js "example.com" "1.1.1.1" "8.8.8.8" "home" "/" "blog" "/blog" ``` -------------------------------- ### Access Root Node Source: https://pkg.go.dev/github.com/BishopFox/jsluice Retrieves the root node of the parsed JavaScript tree. ```go func (a *Analyzer) RootNode() *Node ``` -------------------------------- ### Object Manipulation Source: https://pkg.go.dev/github.com/BishopFox/jsluice Methods for interacting with JavaScript objects represented as nodes. ```APIDOC ## Object Methods ### NewObject Returns a jsluice Object for the given Node. ### AsMap Returns a Go map version of the object. ### GetKeys Returns a slice of all keys in an object. ### GetNode Returns the matching *Node for a given key. ``` -------------------------------- ### URL Type Source: https://pkg.go.dev/github.com/BishopFox/jsluice Defines the URL type for representing URLs found in source code. ```APIDOC ## URL Type ### Description A URL is any URL found in the source code with accompanying details. ### Type Definition type URL struct { URL string `json:"url"` QueryParams []string `json:"queryParams"` BodyParams []string `json:"bodyParams"` Method string `json:"method"` Headers map[string]string `json:"headers,omitempty"` ContentType string `json:"contentType,omitempty"` Type string `json:"type"` // some description like locationAssignment, fetch, $.post or something like that Source string `json:"source,omitempty"` // full source/content of the node; is optional Filename string `json:"filename,omitempty"` // the filename in which the match was found } ``` -------------------------------- ### Extract Secrets from JavaScript Source: https://pkg.go.dev/github.com/BishopFox/jsluice/cmd/jsluice Extract API keys and passwords from JavaScript files using built-in extractors. ```javascript var config = { bucket: "examplebucket", awsKey: "AKIAIOSFODNN7EXAMPLE", awsSecret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", server: "someserver.example.com" }; ``` ```bash ▶ jsluice secrets awskey.js | jq { "kind": "AWSAccessKey", "data": { "key": "AKIAIOSFODNN7EXAMPLE", "secret": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" }, "filename": "awskey.js", "severity": "high", "context": { "awsKey": "AKIAIOSFODNN7EXAMPLE", "awsSecret": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "bucket": "examplebucket", "server": "someserver.example.com" } } ``` -------------------------------- ### ParseUserPatterns Function Source: https://pkg.go.dev/github.com/BishopFox/jsluice Function to parse user-defined patterns from a JSON file. ```APIDOC ## ParseUserPatterns ### Description ParseUserPatterns accepts an io.Reader pointing to a JSON user-pattern definition file, and returns a list of UserPatterns, and any error that occurred. ### Method ParseUserPatterns ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **r** (io.Reader) - Required - An io.Reader pointing to the JSON user-pattern definition file. ### Request Example None ### Response #### Success Response (UserPatterns, error) - **UserPatterns** (UserPatterns) - A list of UserPatterns parsed from the JSON. - **error** (error) - An error if parsing fails, otherwise nil. #### Response Example ```json { "example": [ { "pattern": "example_pattern", "value": "example_value" } ] } ``` ``` -------------------------------- ### URLMatcher Type Source: https://pkg.go.dev/github.com/BishopFox/jsluice Defines the URLMatcher type for matching URLs in the parse tree. ```APIDOC ## URLMatcher Type ### Description A URLMatcher has a type of thing it matches against (e.g. assignment_expression), and a function to actually do the matching and producing of the *URL. ### Type Definition type URLMatcher struct { Type string Fn func(*Node) *URL } ``` ```APIDOC ## AllURLMatchers ### Description AllURLMatchers returns the default list of URLMatchers. ### Method func AllURLMatchers() []URLMatcher ### Endpoint N/A (Function) ### Parameters None ### Request Example None ### Response #### Success Response (200) * **[]URLMatcher** ([]URLMatcher) - A slice of default URLMatcher configurations. #### Response Example None ``` -------------------------------- ### QueryResult Type and Methods Source: https://pkg.go.dev/github.com/BishopFox/jsluice Functions and methods for managing QueryResult, which is a map of capture names to nodes. ```APIDOC ## QueryResult Type ### Description QueryResult is a map of capture names to the corresponding nodes that they matched. ### Type Definition type QueryResult map[string]*Node ``` ```APIDOC ## NewQueryResult ### Description NewQueryResult returns a QueryResult containing the provided *Nodes. ### Method func NewQueryResult(nodes ...*Node) QueryResult ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) * **QueryResult** (QueryResult) - A new QueryResult containing the specified nodes. #### Response Example None ``` ```APIDOC ## QueryResult.Add ### Description Add accepts a *Node and adds it to the QueryResult, provided it has a valid CaptureName. ### Method func (qr QueryResult) Add(n *Node) ### Endpoint N/A (Method on QueryResult type) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **n** (*Node) - Required - The node to add to the QueryResult. ### Request Example None ### Response None ``` ```APIDOC ## QueryResult.Get ### Description Get returns the corresponding *Node for the provided capture name, or nil if no such *Node exists. ### Method func (qr QueryResult) Get(captureName string) *Node ### Endpoint N/A (Method on QueryResult type) ### Parameters #### Path Parameters None #### Query Parameters - **captureName** (string) - Required - The name of the capture to retrieve. #### Request Body None ### Request Example None ### Response #### Success Response (200) * **Node** (*Node) - The node corresponding to the capture name, or nil. #### Response Example None ``` ```APIDOC ## QueryResult.Has ### Description Has returns true if the QueryResult contains a *Node for the provided capture name. ### Method func (qr QueryResult) Has(captureName string) bool ### Endpoint N/A (Method on QueryResult type) ### Parameters #### Path Parameters None #### Query Parameters - **captureName** (string) - Required - The name of the capture to check for. #### Request Body None ### Request Example None ### Response #### Success Response (200) * **bool** (bool) - True if the QueryResult contains the capture name, false otherwise. #### Response Example None ``` -------------------------------- ### Check if a String is a URL Source: https://pkg.go.dev/github.com/BishopFox/jsluice MaybeURL checks if the input string is a valid URL. This function is useful for validating user input or extracted data. ```go func MaybeURL(in string) bool ``` -------------------------------- ### SecretMatcher Type Source: https://pkg.go.dev/github.com/BishopFox/jsluice Defines the SecretMatcher type for finding secrets in the parse tree. ```APIDOC ## SecretMatcher Type ### Description A SecretMatcher is a tree-sitter query to find relevant nodes in the parse tree, and a function to inspect those nodes, returning any Secret that is found. ### Type Definition type SecretMatcher struct { Query string Fn func(*Node) *Secret } ``` -------------------------------- ### UserPatterns Type Definition Source: https://pkg.go.dev/github.com/BishopFox/jsluice UserPatterns is a type alias for a slice of *UserPattern pointers, representing a collection of user-defined patterns. ```go type UserPatterns []*UserPattern ``` -------------------------------- ### Define Expression Placeholder Variable Source: https://pkg.go.dev/github.com/BishopFox/jsluice ExpressionPlaceholder is used to replace expressions during string concatenation collapsing. This is useful for simplifying complex string operations. ```go var ExpressionPlaceholder = "EXPR" ``` -------------------------------- ### Analyzer API Source: https://pkg.go.dev/github.com/BishopFox/jsluice The Analyzer type is the core component for parsing JavaScript and extracting data. ```APIDOC ## NewAnalyzer ### Description Initializes a new Analyzer instance for a given JavaScript source. ### Parameters - **source** ([]byte) - Required - The JavaScript source code. ### Response - ***Analyzer** - A pointer to the initialized Analyzer. ``` -------------------------------- ### Severity Type Source: https://pkg.go.dev/github.com/BishopFox/jsluice Defines the Severity type for indicating the seriousness of a finding. ```APIDOC ## Severity Type ### Description Severity indicates how serious a finding is. ### Type Definition type Severity string ### Constants - **SeverityInfo** (`"info"`) - **SeverityLow** (`"low"`) - **SeverityMedium** (`"medium"`) - **SeverityHigh** (`"high"`) ``` -------------------------------- ### Decode JavaScript String Escapes Source: https://pkg.go.dev/github.com/BishopFox/jsluice DecodeString converts JavaScript-style escape sequences in a string to their literal characters. It handles hex, Unicode, braced Unicode, octal, and single-character escapes. ```go func DecodeString(in string) string ``` -------------------------------- ### Secret Type and Related Functions Source: https://pkg.go.dev/github.com/BishopFox/jsluice Defines the Secret type for representing sensitive data found in JavaScript files and functions to retrieve default secret matchers. ```APIDOC ## Secret Type ### Description A Secret represents any secret or otherwise interesting data found within a JavaScript file. E.g. an AWS access key. ### Type Definition type Secret struct { Kind string `json:"kind"` Data any `json:"data"` Filename string `json:"filename,omitempty"` Severity Severity `json:"severity"` Context any `json:"context"` } ``` ```APIDOC ## AllSecretMatchers ### Description AllSecretMatchers returns the default list of SecretMatchers. ### Method func AllSecretMatchers() []SecretMatcher ### Endpoint N/A (Function) ### Parameters None ### Request Example None ### Response #### Success Response (200) * **[]SecretMatcher** ([]SecretMatcher) - A slice of default SecretMatcher configurations. #### Response Example None ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.