security

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

AllPermissions is the set of all declarable permissions.

Functions

This section is empty.

Types

type FSScope

type FSScope struct {
	Read  []string `json:"read"`
	Write []string `json:"write"`
}

FSScope holds scoped filesystem permission patterns.

type HTTPScope

type HTTPScope struct {
	Allow []string `json:"allow"` // allowed domain patterns (e.g., "*.github.com", "api.example.com")
	Deny  []string `json:"deny"`  // denied domain patterns (checked first)
}

HTTPScope holds scoped HTTP permission patterns.

type Permission

type Permission string

Permission represents an API permission that an app can request.

const (
	PermFS           Permission = "fs"
	PermDialog       Permission = "dialog"
	PermClipboard    Permission = "clipboard"
	PermShell        Permission = "shell"
	PermNotification Permission = "notification"
	PermTray         Permission = "tray"
	PermMenu         Permission = "menu"
	PermHTTP         Permission = "http"
	PermProcess      Permission = "process"
	PermStore        Permission = "store"
	PermShortcuts    Permission = "shortcuts"
	PermUpdater      Permission = "updater"
)

type PermissionError

type PermissionError struct {
	Namespace string
	Method    string
	Attempted string
	Allowed   []string
	ConfigKey string
}

PermissionError is a structured permission denial error with AI-debuggable output.

func (*PermissionError) Error

func (e *PermissionError) Error() string

Error returns the AI-friendly formatted error message.

type Policy

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

Policy holds the security policy for a running app.

func DevPolicy

func DevPolicy() *Policy

DevPolicy creates a permissive policy for development mode.

func NewPolicy

func NewPolicy(perms []string, projectDir string, appName string, devMode bool) *Policy

NewPolicy creates a security policy from the declared permissions.

func (*Policy) AllowDir

func (p *Policy) AllowDir(dir string)

AllowDir adds an additional allowed directory (e.g., user-selected via dialog).

func (*Policy) Check

func (p *Policy) Check(perm Permission) error

Check returns an error if the given permission is not granted.

func (*Policy) CheckFSRead

func (p *Policy) CheckFSRead(path string) error

CheckFSRead verifies that the path is allowed for reading.

func (*Policy) CheckFSWrite

func (p *Policy) CheckFSWrite(path string) error

CheckFSWrite verifies that the path is allowed for writing.

func (*Policy) CheckHTTP

func (p *Policy) CheckHTTP(rawURL string) error

CheckHTTP verifies that an HTTP request to the given URL is allowed.

func (*Policy) CheckPath

func (p *Policy) CheckPath(path string) error

CheckPath verifies that a file path is within the allowed directories. It resolves symlinks to prevent traversal attacks.

func (*Policy) CheckProcess

func (p *Policy) CheckProcess(cmd string, args []string) error

CheckProcess verifies that a command execution is allowed.

func (*Policy) HasPermission

func (p *Policy) HasPermission(perm Permission) bool

HasPermission checks if a permission is granted without returning an error.

func (*Policy) SetFSScope

func (p *Policy) SetFSScope(scope FSScope)

SetFSScope configures scoped filesystem permissions with glob patterns.

func (*Policy) SetHTTPScope

func (p *Policy) SetHTTPScope(scope HTTPScope)

SetHTTPScope configures scoped HTTP permissions with domain patterns.

func (*Policy) SetProcessScope

func (p *Policy) SetProcessScope(scope ProcessScope)

SetProcessScope configures scoped process execution permissions.

type ProcessRule

type ProcessRule struct {
	Cmd  string   `json:"cmd"`
	Args []string `json:"args"` // if empty or contains "*", any args allowed
}

ProcessRule defines an allowed command and its permitted arguments.

type ProcessScope

type ProcessScope struct {
	Exec []ProcessRule `json:"exec"`
}

ProcessScope holds scoped process execution permissions.

Jump to

Keyboard shortcuts

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