psdata

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package psdata builds PowerShell scripts in which caller-supplied values are carried as data rather than interpolated into the script as source text.

It lives in its own package, rather than beside either caller, because both pkg/windows (the tool layer) and internal/desktop (the engine) assemble PowerShell and pkg/windows already imports internal/desktop — so a shared helper in either one would be a cycle or a copy. A security primitive that exists twice is one that gets fixed once, so it exists here instead.

The package is deliberately untagged: it is pure string assembly with no Windows dependency, so its injection-safety tests run on any platform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder assembles a PowerShell script in which every caller-supplied value is bound to a variable carrying base64 data.

Quoting is not a viable defence here, which is why this type exists. The PowerShell lexer closes a single-quoted literal on U+2018, U+2019, U+201A and U+201B as well as on U+0027, so an escaper that doubles only the ASCII apostrophe lets a value containing a typographic quote terminate its literal and begin a new statement. -EncodedCommand does not help: the injection is in the script text before it is encoded.

Binding removes the class rather than enumerating it. Base64's alphabet is [A-Za-z0-9+/=], which holds no character the lexer treats as a delimiter, so a bound value cannot be parsed as code however it is spelled — and it never passes through the lexer at all.

The zero value is ready to use.

func (*Builder) Arg

func (s *Builder) Arg(v string) string

Arg binds v and returns the variable reference to use in the script body.

A variable in argument position is passed as a single value and is not re-tokenized, so a value beginning with "-" is bound as an argument and never read as a parameter name. Call Arg for every caller-supplied value; never concatenate one into the body directly.

func (*Builder) Script

func (s *Builder) Script(body string) string

Script returns body prefixed by the bindings Arg created, so the variables are in scope. With no bindings it returns body unchanged.

Jump to

Keyboard shortcuts

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