sourcemap

package
v1.39.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sourcemap fetches and caches JavaScript source maps and resolves minified frames (url, line, column) → original (file, line, function).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAllowedURL

func IsAllowedURL(u string, allowedHosts []string) bool

IsAllowedURL reports whether u has an http or https scheme and its host exactly matches one of the allowedHosts entries. Subdomain-prefix attacks (evil.com/cdn.example.com/...) and suffix attacks (cdn.example.com.evil.io/...) are both rejected by the trailing-slash anchor.

Types

type Frame

type Frame struct {
	File     string `json:"file"`
	Line     int    `json:"line"`
	Column   int    `json:"column"`
	Function string `json:"function,omitempty"`
}

Frame is a resolved original-source location.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver fetches and caches source maps. Safe for concurrent use.

func NewResolver

func NewResolver(client *http.Client, maxSize int, ttl time.Duration, maxBodyBytes int) *Resolver

NewResolver creates a Resolver. maxSize is the FIFO-by-insertion-time bound (entries evicted oldest-first when full), ttl is per-entry expiry duration, maxBodyBytes caps how many bytes of a source map response are read.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, jsURL string, line, column int) (*Frame, error)

Resolve takes the URL of a minified JS bundle plus 1-based line and column (matching browser stack-frame convention), fetches its companion .map file, and returns the original frame. Source map URL is derived as jsURL+".map".

The returned Frame.File is the path component of the resolved source: the go-sourcemap library resolves relative source paths against the map URL's origin, so we strip that origin prefix to return a clean relative path.

Jump to

Keyboard shortcuts

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