Walk An Isolated Subtree With fs.Sub And WalkDir
Mount a narrow directory view with fs.Sub, prune temporary folders via fs.WalkDir and fs.SkipDir, and verify parent escapes fail.
Treat every input as untrusted: contain paths, isolate secrets, and avoid shell injection.
276 published examples — showing latest 48
Mount a narrow directory view with fs.Sub, prune temporary folders via fs.WalkDir and fs.SkipDir, and verify parent escapes fail.
Sign canonical webhook payloads using crypto/hmac with SHA-256 and validate hex signatures in constant time via hmac.Equal against tampering.
Inspect identifier runes against unicode.Latin, unicode.Cyrillic, and custom Range16 tables via unicode.In to block mixed-script spoofing attempts.
Resolve relative, protocol-relative, and external redirect strings against a base net/url.URL, then enforce same-scheme and same-host checks.
Share buffer bytes across independent cursors with duplicate() and hand untrusted callers immutable views via asReadOnlyBuffer() safely.
Inspect sealed interfaces at runtime with Class.isSealed() and getPermittedSubclasses() to build a closed allowlist before reflection dispatch.
Convert internationalized domain names between Unicode and ASCII Punycode via java.net.IDN, enforcing STD3 rules to reject unsafe host characters.
Issue temporary object handles with Proxy.revocable and call revoke() when a task ends so subsequent property reads, writes, and in checks throw TypeError.
Invoke functions with an explicit this receiver and argument array via Reflect.apply, avoiding collisions when objects shadow .apply or lack Function methods.
Verify required scopes and mutual-exclusion rules cleanly with ES2025 Set.prototype.isSubsetOf, isSupersetOf, and isDisjointFrom without array copies.
Detect lone UTF-16 surrogates with String.prototype.isWellFormed before calling encodeURIComponent, using toWellFormed only when lossy repair fits.
Implement Symbol.replace on a custom matcher object so String.prototype.replace runs literal token redaction without dynamic RegExp compilation.
Audit text replacements in one pass with re.subn returning (text, count), and scan bounded slices using compiled pattern pos and endpos offsets.
Subclass string.Formatter to allowlist lookup keys, block attribute traversal in format strings, and mask sensitive values automatically.
Write generic functions over AsRef<Path> to accept any path-like input and Borrow<Q> to query PathBuf HashMap keys using borrowed &Path.
Resolve relative . and .. segments purely in memory via Path::components while rejecting root prefixes and traversals escaping above the sandbox.
Build a zero-cost compile-time typestate pipeline using PhantomData<State> in 100% safe Rust so invalid transitions fail before runtime.
Attach WITH (security_barrier = true) to PostgreSQL views so outer non-leakproof predicates cannot run ahead of row-hiding WHERE filters.
Contrast WITH LOCAL CHECK OPTION against CASCADED on stacked views to see when writes enforce parent view filters versus only the top view.
Expose ReadonlySet views across module boundaries to hide add, delete, and clear from callers while preserving lookup, iteration, and element covariance.
Compute replacements at runtime with a function passed to replace, where the callback receives the match, capture groups, offset, and the full string.
Shift letters by a fixed offset using u8 arithmetic on ASCII ranges, wrapping inside each case so digits and punctuation stay untouched.
SET ROLE changes the effective user inside a session, RESET ROLE returns to the login role, and privileges flip with each switch.
A Record keyed by a role union forces every entry to exist, so reading table[role] never returns undefined and capability checks need no runtime fallback.
Implement fmt.GoStringer so the %#v verb prints a redacted summary for credential-bearing types instead of leaking password fields into debug logs.
Parse and build host:port pairs with netip.AddrPort, keeping address and port as typed fields instead of splitting strings by hand.
Pick url.PathEscape for a single path segment and url.QueryEscape for a query value, since the two sets of reserved characters differ.
Rewrite JSON log fields with slog.HandlerOptions.ReplaceAttr: rename the time key, lowercase levels, and redact sensitive keys before they reach output.
Flip Windows hidden and read-only flags on a file through DosFileAttributeView, then prove the read-only attribute rejects rewrites until you clear it.
Encrypt and decrypt payloads with RSA-OAEP via Cipher, passing an explicit OAEPParameterSpec so the digest and MGF1 hash never depend on provider defaults.
Count character frequencies and sum -p log2 p to score repeat-heavy strings near zero bits per character — a rough signal, not a security verdict.
Derive HOTP and TOTP one-time codes from HMAC-SHA1 with dynamic truncation, checking the published RFC 4226 and RFC 6238 test vectors end to end.
JSON.parse defines __proto__ as an ordinary own property, but assigning that key hits the setter and hijacks the target object, so merges must reject it.
Hand strings to C code through CString: interior NUL bytes are rejected with the offending bytes, and valid values carry exactly one terminating NUL.
pgp_sym_encrypt seals text into a bytea with a passphrase and pgp_sym_decrypt opens it; random session keys make identical plaintexts encrypt differently.
Turn a block cipher into a stream with cipher.NewCTR: one keystream per direction, XORKeyStream both ways, and why an IV must never repeat under the same key.
Chmod changes a file's permission bits and Stat reads them back, so secret files can drop to owner-only 0600 before any data is written.
Resolve command names through exec.LookPath, handle the ErrNotFound path, and see why names containing separators bypass the PATH search.
os.FileMode packs type and permission bits: String renders them rwx style, Perm strips the type bits, and IsDir or IsRegular classify the mode.
Validate path shape with fs.ValidPath before any fs.FS read, rejecting absolute paths, dot segments, and empty elements at the gate.
encoding/json silently drops unexported struct fields, and the json:"-" tag excludes exported ones from both marshal and unmarshal roundtrips.
Wrap any handler with middleware that injects nosniff, frame-deny, referrer and CSP headers so every response ships the same baseline defenses.
Compare auth scheme names with strings.EqualFold so Bearer, BEARER and bearer all route correctly; credentials themselves need a constant-time compare.
Generate an ECDSA key, issue a self-signed certificate with CreateCertificate, parse the DER back with ParseCertificate, and encode it as PEM.
Sign a payload with the Ed25519 JCA Signature API and verify both the original bytes and a tampered copy, which must fail.
Wrap a record payload in a SealedObject under AES/GCM, then getObject with the key to reconstruct it from the stored algorithm parameters.
Serialize an invariant-bearing object through a serialization proxy so the constructor validation always runs on read.
CSS.escape renders arbitrary ids and user-derived strings safe inside querySelector, where an unescaped colon or dot throws SyntaxError.
Showing 48 of 276 verified Security Boundaries examples. Filter the full catalog by language, framework, or keyword in Explore.
Browse & filter all 276 examples in Explore →