store

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package store persists flow metadata in SQLite and bodies on disk.

Index

Constants

View Source
const (
	FlagIntercepted  int64 = 1 << iota // request passed through the intercept hold queue
	FlagEdited                         // request was edited before forwarding
	FlagDropped                        // request was dropped by the user (not forwarded)
	FlagCaptureError                   // a body could not be captured; forwarding still succeeded
	FlagTLSFailed                      // TLS interception failed for this flow
	FlagWebSocket                      // a protocol-upgrade (WebSocket) handshake, tunneled transparently
	FlagRepeater                       // a request sent from the Repeater module
	FlagIntruder                       // a request sent from the Intruder module
	FlagImported                       // a flow imported from a HAR file (not proxied)
	FlagActiveScan                     // a probe sent by the active scanner
)

Flow flag bits, OR'd into Flow.Flags.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID      int64  `json:"id"`
	Label   string `json:"label"`
	Prefix  string `json:"prefix"`
	Created int64  `json:"created"` // unix millis
}

APIKey is metadata for an issued control-API key. The secret token itself is never stored — only its SHA-256 hash and a short identifying prefix.

type BodyWriter

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

BodyWriter streams bytes to a temp file while hashing them, then commits the file to a content-addressed path on Finalize. Safe for bounded memory: bytes are never buffered whole.

func (*BodyWriter) Abort

func (w *BodyWriter) Abort()

Abort discards an in-progress body (e.g. on error).

func (*BodyWriter) Finalize

func (w *BodyWriter) Finalize() (string, int64, error)

Finalize commits the body and returns its sha256 hex hash and byte length. If a body with the same hash already exists it is deduplicated.

func (*BodyWriter) Write

func (w *BodyWriter) Write(p []byte) (int, error)

Write implements io.Writer.

type Flow

type Flow struct {
	ID          int64
	TS          time.Time
	Method      string
	Scheme      string
	Host        string
	Port        int
	Path        string
	HTTPVersion string
	Status      int
	ReqHeaders  map[string][]string
	ResHeaders  map[string][]string
	ReqBodyHash string
	ResBodyHash string
	ReqLen      int64
	ResLen      int64
	Mime        string
	DurationMs  int64
	ClientAddr  string
	Error       string
	Flags       int64
}

Flow is one captured request/response exchange. Bodies are referenced by content hash, never embedded.

type FlowFilter

type FlowFilter struct {
	Limit        int    // max rows (defaults to 200 when <= 0)
	BeforeID     int64  // cursor: only rows with id < BeforeID (0 = newest)
	Method       string // exact method match
	Host         string // case-insensitive substring of host
	Search       string // case-insensitive substring of path
	Scheme       string // exact scheme match ("http"/"https")
	StatusClass  int    // 1..5 → 1xx..5xx; 0 = any
	RequireFlags int64  // only rows with any of these flag bits set
	ExcludeFlags int64  // only rows with none of these flag bits set
}

FlowFilter selects and pages flows. Zero-valued fields are ignored.

type Issue

type Issue struct {
	ID       int64  `json:"id"`
	FlowID   int64  `json:"flowId"`
	Severity string `json:"severity"`
	Title    string `json:"title"`
	Target   string `json:"target"`
	Detail   string `json:"detail"`
	Evidence string `json:"evidence"`
	Fix      string `json:"fix"`
}

Issue is one scanner finding. Severity is "High" | "Medium" | "Low" | "Info".

type Rule

type Rule struct {
	ID      int64
	Ord     int
	Enabled bool
	Type    string
	Match   string
	Replace string
}

Rule is one ordered match-&-replace transform. Type is one of "req-header", "req-body" (response-side types are reserved for a later slice).

type SavedView

type SavedView struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Data string `json:"data"`
}

SavedView is a named history filter (its Data is an opaque JSON blob the UI understands: scheme/method/status/search/host/inScope).

type ScopeRule

type ScopeRule struct {
	ID      int64  `json:"id"`
	Ord     int    `json:"ord"`
	Enabled bool   `json:"enabled"`
	Action  string `json:"action"`
	Host    string `json:"host"`
	Path    string `json:"path"`
	Scheme  string `json:"scheme"`
	Port    int    `json:"port"`
}

ScopeRule is one target-scope rule. Action is "include" | "exclude". Empty host/path/scheme and port 0 mean "any" for that field.

type Store

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

Store owns the SQLite database and the on-disk body directory.

func Open

func Open(dir string) (*Store, error)

Open creates (or opens) the database and body store under dir.

func (*Store) ClearIssues

func (s *Store) ClearIssues() error

ClearIssues removes all issues.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) CreateAPIKey

func (s *Store) CreateAPIKey(label string) (token string, key APIKey, err error)

CreateAPIKey mints a new key, returning the full token (shown to the user once) and its stored metadata. The token is "ick_" + 48 hex chars.

func (*Store) CreateRule

func (s *Store) CreateRule(r *Rule) (int64, error)

CreateRule inserts a rule and returns its id.

func (*Store) CreateScopeRule

func (s *Store) CreateScopeRule(r *ScopeRule) (int64, error)

CreateScopeRule inserts a scope rule and returns its id.

func (*Store) CreateView

func (s *Store) CreateView(v *SavedView) (int64, error)

CreateView stores a named view and returns its id.

func (*Store) DeleteAPIKey

func (s *Store) DeleteAPIKey(id int64) error

DeleteAPIKey revokes a key by id.

func (*Store) DeleteRule

func (s *Store) DeleteRule(id int64) error

DeleteRule removes a rule by id.

func (*Store) DeleteScopeRule

func (s *Store) DeleteScopeRule(id int64) error

DeleteScopeRule removes a scope rule by id.

func (*Store) DeleteView

func (s *Store) DeleteView(id int64) error

DeleteView removes a view by id.

func (*Store) GetFlow

func (s *Store) GetFlow(id int64) (*Flow, error)

GetFlow loads a single flow by id.

func (*Store) GetSetting

func (s *Store) GetSetting(key string) (string, bool, error)

GetSetting returns the value and whether it was present.

func (*Store) InsertFlow

func (s *Store) InsertFlow(f *Flow) (int64, error)

InsertFlow stores a new flow and sets f.ID to the assigned row id.

func (*Store) ListAPIKeys

func (s *Store) ListAPIKeys() ([]APIKey, error)

ListAPIKeys returns all key metadata (never the token or hash), newest first.

func (*Store) ListIssues

func (s *Store) ListIssues() ([]Issue, error)

ListIssues returns all issues ordered by severity (High→Info) then id.

func (*Store) ListRules

func (s *Store) ListRules() ([]Rule, error)

ListRules returns all rules ordered by ord then id.

func (*Store) ListScopeRules

func (s *Store) ListScopeRules() ([]ScopeRule, error)

ListScopeRules returns scope rules ordered by ord then id.

func (*Store) ListViews

func (s *Store) ListViews() ([]SavedView, error)

ListViews returns saved views, newest first.

func (*Store) NewBodyWriter

func (s *Store) NewBodyWriter() (*BodyWriter, error)

NewBodyWriter starts a new body capture.

func (*Store) OpenBody

func (s *Store) OpenBody(sum string) (io.ReadCloser, error)

OpenBody returns a reader for the body with the given hash. An empty hash yields an empty reader (no body).

func (*Store) QueryFlows

func (s *Store) QueryFlows(limit int) ([]*Flow, error)

QueryFlows returns up to limit flows, newest first.

func (*Store) QueryFlowsFilter

func (s *Store) QueryFlowsFilter(f FlowFilter) ([]*Flow, error)

QueryFlowsFilter returns flows matching f, newest first. Filtering and paging are pushed down to SQL so large histories never materialize in memory.

func (*Store) QueryWSFrames

func (s *Store) QueryWSFrames(flowID int64, limit int) ([]*WSFrame, error)

QueryWSFrames returns up to limit frames for a flow, oldest first.

func (*Store) SaveIssues

func (s *Store) SaveIssues(issues []Issue) error

SaveIssues upserts issues, deduplicated by (title, target).

func (*Store) SaveWSFrame

func (s *Store) SaveWSFrame(f *WSFrame) error

SaveWSFrame records a captured frame.

func (*Store) SetSetting

func (s *Store) SetSetting(key, value string) error

SetSetting upserts a key/value setting.

func (*Store) UpdateRule

func (s *Store) UpdateRule(r *Rule) error

UpdateRule overwrites the rule identified by r.ID.

func (*Store) UpdateScopeRule

func (s *Store) UpdateScopeRule(r *ScopeRule) error

UpdateScopeRule overwrites the rule identified by r.ID.

func (*Store) VerifyAPIKey

func (s *Store) VerifyAPIKey(token string) (bool, error)

VerifyAPIKey reports whether token matches a stored key (constant work via the hash index). Intended for gating remote control-API access.

type WSFrame

type WSFrame struct {
	ID      int64     `json:"id"`
	FlowID  int64     `json:"flowId"`
	TS      time.Time `json:"-"`
	Dir     string    `json:"dir"`
	Opcode  int       `json:"opcode"`
	Length  int64     `json:"length"`
	Preview string    `json:"preview"`
}

WSFrame is one captured WebSocket frame. Dir is "send" (client→server) or "recv" (server→client). Preview holds a bounded prefix of the (unmasked) payload; Length is the full frame payload length.

Jump to

Keyboard shortcuts

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