Sharp Edges
Trail of BitsOfficialPublished by Trail of Bits
- Skill
- Guidelines
- Security
- CC-BY-SA-4.0
- Medium risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
Sharp Edges is a systematic analysis framework designed to identify 'footguns'—design patterns in APIs, libraries, and configurations that make it easy for developers to inadvertently introduce security flaws. By focusing on the 'pit of success' principle, this skill helps auditors and developers ensure that the path of least resistance is also the most secure one. It provides a structured workflow to probe for common pitfalls like weak algorithm selection, insecure defaults, silent failures, and type confusion, moving beyond simple bug hunting to address the root causes of developer-induced security mistakes.
What it does
- Maps security-relevant APIs and configuration schemas for potential misuse.
- Probes for edge cases like zero, null, or negative values that bypass security logic.
- Evaluates whether default settings are secure by design.
- Identifies cryptographic and authentication patterns prone to developer error.
- Assesses the risk of silent failures and stringly-typed security interfaces.
- Classifies findings by severity based on how easily a developer can trigger a vulnerability.
When to use it
- During the design phase of new APIs or configuration schemas.
- When auditing cryptographic library ergonomics and usage patterns.
- When reviewing authentication and authorization interfaces.
- When assessing whether code follows secure-by-default principles.
- When evaluating the impact of developer-facing configuration options.
Advantages
- Focuses on design-level flaws rather than just implementation bugs.
- Promotes the 'pit of success' by identifying where secure usage is difficult.
- Provides a repeatable, four-phase workflow for consistent analysis.
- Helps prevent common security mistakes like algorithm confusion and insecure defaults.
- Encourages the creation of misuse-resistant APIs.
Usage examples
- “Analyze this authentication library for potential sharp edges.”
- The agent will identify if the library allows empty passwords, uses predictable token generation, or has insecure default session timeouts.
- “Review this configuration schema for dangerous options.”
- The agent will flag boolean flags that disable security, unvalidated constructor parameters, or magic values that could lead to catastrophic failure.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/trailofbits/sharp-edges/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip sharp-edges.zip -d .agents/skills
Documentation by Trail of Bits
Sharp Edges Analysis
Evaluates whether APIs, configurations, and interfaces are resistant to developer misuse. Identifies designs where the "easy path" leads to insecurity.
When to Use
Reviewing API or library design decisions
Auditing configuration schemas for dangerous options
Evaluating cryptographic API ergonomics
Assessing authentication/authorization interfaces
Reviewing any code that exposes security-relevant choices to developers
When NOT to Use
Implementation bugs (use standard code review)
Business logic flaws (use domain-specific analysis)
Performance optimization (different concern)
Agent
The sharp-edges-analyzer agent runs the full sharp edges analysis workflow autonomously. Use it when you want a dedicated analysis of APIs, configurations, or interfaces for misuse resistance and footgun potential. The agent follows the four-phase workflow (Surface Identification, Edge Case Probing, Threat Modeling, Validate Findings) and reads language-specific references on demand.
Core Principle
The pit of success: Secure usage should be the path of least resistance. If developers must understand cryptography, read documentation carefully, or remember special rules to avoid vulnerabilities, the API has failed.
Rationalizations to Reject
| Rationalization | Why It's Wrong | Required Action |
|---|---|---|
| "It's documented" | Developers don't read docs under deadline pressure | Make the secure choice the default or only option |
| "Advanced users need flexibility" | Flexibility creates footguns; most "advanced" usage is copy-paste | Provide safe high-level APIs; hide primitives |
| "It's the developer's responsibility" | Blame-shifting; you designed the footgun | Remove the footgun or make it impossible to misuse |
| "Nobody would actually do that" | Developers do everything imaginable under pressure | Assume maximum developer confusion |
| "It's just a configuration option" | Config is code; wrong configs ship to production | Validate configs; reject dangerous combinations |
| "We need backwards compatibility" | Insecure defaults can't be grandfather-claused | Deprecate loudly; force migration |
Sharp Edge Categories
1. Algorithm/Mode Selection Footguns
APIs that let developers choose algorithms invite choosing wrong ones.
The JWT Pattern (canonical example):
Header specifies algorithm: attacker can set
"alg": "none"to bypass signaturesAlgorithm confusion: RSA public key used as HMAC secret when switching RS256→HS256
Root cause: Letting untrusted input control security-critical decisions
Detection patterns:
Function parameters like
algorithm,mode,cipher,hash_typeEnums/strings selecting cryptographic primitives
Configuration options for security mechanisms
Example - PHP password_hash allowing weak algorithms:
// DANGEROUS: allows crc32, md5, sha1
password_hash($password, PASSWORD_DEFAULT); // Good - no choice
hash($algorithm, $password); // BAD: accepts "crc32"2. Dangerous Defaults
Defaults that are insecure, or zero/empty values that disable security.
The OTP Lifetime Pattern:
# What happens when lifetime=0?
def verify_otp(code, lifetime=300): # 300 seconds default
if lifetime == 0:
return True # OOPS: 0 means "accept all"?
# Or does it mean "expired immediately"?Detection patterns:
Timeouts/lifetimes that accept 0 (infinite? immediate expiry?)
Empty strings that bypass checks
Null values that skip validation
Boolean defaults that disable security features
Negative values with undefined semantics
Questions to ask:
What happens with
timeout=0?max_attempts=0?key=""?Is the default the most secure option?
Can any default value disable security entirely?
3. Primitive vs. Semantic APIs
APIs that expose raw bytes instead of meaningful types invite type confusion.
The Libsodium vs. Halite Pattern:
// Libsodium (primitives): bytes are bytes
sodium_crypto_box($message, $nonce, $keypair);
// Easy to: swap nonce/keypair, reuse nonces, use wrong key type
// Halite (semantic): types enforce correct usage
Crypto::seal($message, new EncryptionPublicKey($key));
// Wrong key type = type error, not silent failureDetection patterns:
Functions taking
bytes,string,[]bytefor distinct security conceptsParameters that could be swapped without type errors
Same type used for keys, nonces, ciphertexts, signatures
The comparison footgun:
// Timing-safe comparison looks identical to unsafe
if hmac == expected { } // BAD: timing attack
if hmac.Equal(mac, expected) { } // Good: constant-time
// Same types, different security properties4. Configuration Cliffs
One wrong setting creates catastrophic failure, with no warning.
Detection patterns:
Boolean flags that disable security entirely
String configs that aren't validated
Combinations of settings that interact dangerously
Environment variables that override security settings
Constructor parameters with sensible defaults but no validation (callers can override with insecure values)
Examples:
# One typo = disaster
verify_ssl: fasle # Typo silently accepted as truthy?
# Magic values
session_timeout: -1 # Does this mean "never expire"?
# Dangerous combinations accepted silently
auth_required: true
bypass_auth_for_health_checks: true
health_check_path: "/" # Oops// Sensible default doesn't protect against bad callers
public function __construct(
public string $hashAlgo = 'sha256', // Good default...
public int $otpLifetime = 120, // ...but accepts md5, 0, etc.
) {}See config-patterns.md for detailed patterns.
5. Silent Failures
Errors that don't surface, or success that masks failure.
Detection patterns:
Functions returning booleans instead of throwing on security failures
Empty catch blocks around security operations
Default values substituted on parse errors
Verification functions that "succeed" on malformed input
Examples:
# Silent bypass
def verify_signature(sig, data, key):
if not key:
return True # No key = skip verification?!
# Return value ignored
signature.verify(data, sig) # Throws on failure
crypto.verify(data, sig) # Returns False on failure
# Developer forgets to check return value6. Stringly-Typed Security
Security-critical values as plain strings enable injection and confusion.
Detection patterns:
SQL/commands built from string concatenation
Permissions as comma-separated strings
Roles/scopes as arbitrary strings instead of enums
URLs constructed by joining strings
The permission accumulation footgun:
permissions = "read,write"
permissions += ",admin" # Too easy to escalate
# vs. type-safe
permissions = {Permission.READ, Permission.WRITE}
permissions.add(Permission.ADMIN) # At least it's explicitAnalysis Workflow
Phase 1: Surface Identification
Map security-relevant APIs: authentication, authorization, cryptography, session management, input validation
Identify developer choice points: Where can developers select algorithms, configure timeouts, choose modes?
Find configuration schemas: Environment variables, config files, constructor parameters
Phase 2: Edge Case Probing
For each choice point, ask:
Zero/empty/null: What happens with
0,"",null,[]?Negative values: What does
-1mean? Infinite? Error?Type confusion: Can different security concepts be swapped?
Default values: Is the default secure? Is it documented?
Error paths: What happens on invalid input? Silent acceptance?
Phase 3: Threat Modeling
Consider three adversaries:
The Scoundrel: Actively malicious developer or attacker controlling config
Can they disable security via configuration?
Can they downgrade algorithms?
Can they inject malicious values?
The Lazy Developer: Copy-pastes examples, skips documentation
Will the first example they find be secure?
Is the path of least resistance secure?
Do error messages guide toward secure usage?
The Confused Developer: Misunderstands the API
Can they swap parameters without type errors?
Can they use the wrong key/algorithm/mode by accident?
Are failure modes obvious or silent?
Phase 4: Validate Findings
For each identified sharp edge:
Reproduce the misuse: Write minimal code demonstrating the footgun
Verify exploitability: Does the misuse create a real vulnerability?
Check documentation: Is the danger documented? (Documentation doesn't excuse bad design, but affects severity)
Test mitigations: Can the API be used safely with reasonable effort?
If a finding seems questionable, return to Phase 2 and probe more edge cases.
Severity Classification
| Severity | Criteria | Examples |
|---|---|---|
| Critical | Default or obvious usage is insecure | verify: false default; empty password allowed |
| High | Easy misconfiguration breaks security | Algorithm parameter accepts "none" |
| Medium | Unusual but possible misconfiguration | Negative timeout has unexpected meaning |
| Low | Requires deliberate misuse | Obscure parameter combination |
References
By category:
Cryptographic APIs: See references/crypto-apis.md
Configuration Patterns: See references/config-patterns.md
Authentication/Session: See references/auth-patterns.md
Real-World Case Studies: See references/case-studies.md (OpenSSL, GMP, etc.)
By language (general footguns, not crypto-specific):
| Language | Guide |
|---|---|
| C/C++ | references/lang-c.md |
| Go | references/lang-go.md |
| Rust | references/lang-rust.md |
| Swift | references/lang-swift.md |
| Java | references/lang-java.md |
| Kotlin | references/lang-kotlin.md |
| C# | references/lang-csharp.md |
| PHP | references/lang-php.md |
| JavaScript/TypeScript | references/lang-javascript.md |
| Python | references/lang-python.md |
| Ruby | references/lang-ruby.md |
See also references/language-specific.md for a combined quick reference.
Quality Checklist
Before concluding analysis:
[ ] Probed all zero/empty/null edge cases
[ ] Verified defaults are secure
[ ] Checked for algorithm/mode selection footguns
[ ] Tested type confusion between security concepts
[ ] Considered all three adversary types
[ ] Verified error paths don't bypass security
[ ] Checked configuration validation
[ ] Constructor params validated (not just defaulted) - see config-patterns.md
Files
- ATTRIBUTION.mdAdded by AutoGineer927 B
- LICENSELicence file added by AutoGineer19.7 KiB
- SKILL.md11.5 KiB
- agents/openai.yaml239 B
- assets/trail-of-bits-mark.svg3.0 KiB
- references/auth-patterns.md6.8 KiB
- references/case-studies.md8.0 KiB
- references/config-patterns.md9.5 KiB
- references/crypto-apis.md5.2 KiB
- references/lang-c.md5.5 KiB
- references/lang-csharp.md7.2 KiB
- references/lang-go.md6.5 KiB
- references/lang-java.md6.7 KiB
- references/lang-javascript.md6.8 KiB
- references/lang-kotlin.md6.6 KiB
- references/lang-php.md6.0 KiB
- references/lang-python.md6.5 KiB
- references/lang-ruby.md6.1 KiB
- references/lang-rust.md6.4 KiB
- references/lang-swift.md6.1 KiB
- references/language-specific.md13.0 KiB
references/case-studies.md
Real-World Case Studies
Analysis of sharp edges in widely-used libraries. These aren't implementation bugs—they're design decisions that make secure usage difficult.
GNU Multiple Precision Arithmetic Library (GMP)
GMP is used extensively for cryptographic implementations (RSA, Paillier, ElGamal, etc.) despite being fundamentally unsuitable for cryptography.
Sharp Edge: Variable-Time Operations
The Problem: GMP operations are not constant-time. Timing varies based on input values.
// DANGEROUS: Timing leaks secret exponent bits
mpz_powm(result, base, secret_exponent, modulus);
// Each bit of secret_exponent affects timing differently
// Attacker can recover secret_exponent via timing analysisWhy This Matters:
Paillier encryption uses
mpz_powmwith secret keysRSA implementations using GMP leak private key bits
Even "blinded" implementations often have residual timing leaks
Detection Pattern: Any use of GMP (mpz_* functions) with secret values:
mpz_powm,mpz_powm_sec(the "sec" version is still not fully constant-time)mpz_mul,mpz_modwith secret operandsmpz_cmpfor secret comparison
Real Vulnerabilities:
CVE-2018-16152: Timing attack on strongSwan IKEv2
Numerous academic papers demonstrating key recovery from GMP-based crypto
Sharp Edge: Memory Not Securely Cleared
mpz_t secret_key;
mpz_init(secret_key);
// ... use secret_key ...
mpz_clear(secret_key); // Memory NOT securely wiped
// Secret data may persist in freed memoryThe Problem: mpz_clear doesn't zero memory before freeing. Secrets persist.
Sharp Edge: Confusing Import/Export API
// What does this do?
mpz_export(buf, &count, order, size, endian, nails, op);
// Parameters:
// - order: 1 = most significant word first, -1 = least significant
// - endian: 1 = big, -1 = little, 0 = native
// - nails: bits to skip at top of each word (?!)The Problem: Seven parameters, three of which control byte ordering in different ways. Easy to get wrong, hard to verify correctness.
Mitigation
For cryptographic use, prefer:
libsodium for common operations
OpenSSL BIGNUM (has constant-time variants)
libgmp with mpz_powm_sec (partial mitigation, not complete)
OpenSSL
The canonical example of a powerful but footgun-laden cryptographic library.
Sharp Edge: SSL_CTX_set_verify Callback
// DANGEROUS: Easy to write callback that always returns 1
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, verify_callback);
int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
// Developer thinks: "I'll add logging here"
log_certificate(ctx);
return 1; // OOPS: Always accepts, ignoring preverify_ok!
}The Problem: The callback's return value determines whether verification succeeds. Developers often:
Return 1 (success) unconditionally while "just adding logging"
Forget that returning non-zero bypasses all verification
Copy-paste examples that return 1 for "debugging"
Correct Pattern:
int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) {
if (!preverify_ok) {
// Log failure details
log_verification_failure(ctx);
}
return preverify_ok; // Preserve original decision
}Sharp Edge: Error Handling via ERR_get_error
// DANGEROUS: Error easily ignored
EVP_EncryptFinal_ex(ctx, outbuf, &outlen);
// Did it succeed? Who knows!
// Correct but verbose:
if (EVP_EncryptFinal_ex(ctx, outbuf, &outlen) != 1) {
unsigned long err = ERR_get_error();
char buf[256];
ERR_error_string_n(err, buf, sizeof(buf));
// Handle error...
}The Problem:
Functions return 1 for success (not 0!)
Errors accumulate in a thread-local queue
Easy to forget to check, easy to check wrong way
Error queue must be cleared or errors persist
Sharp Edge: RAND_bytes vs RAND_pseudo_bytes
// These look almost identical:
RAND_bytes(buf, len); // Cryptographically secure
RAND_pseudo_bytes(buf, len); // NOT guaranteed secure!
// Worse: RAND_pseudo_bytes returns 1 even when insecure
int rc = RAND_pseudo_bytes(buf, len);
// rc == 1 means "success", not "cryptographically random"
// rc == 0 means "success but not crypto-strength" (!!)
// rc == -1 means "not supported"The Problem: Function names differ by one word; return values are confusing; the insecure function is not clearly marked dangerous.
Sharp Edge: Memory Ownership Confusion
// Who frees this?
X509 *cert = SSL_get_peer_certificate(ssl);
// Answer: YOU do (it's a copy)
// Who frees this?
X509 *cert = SSL_get0_peer_certificate(ssl); // OpenSSL 3.0+
// Answer: NOBODY (it's a reference)
// The difference: "get" vs "get0"
// This convention is NOT obvious or consistently appliedThe Problem: Memory ownership indicated by subtle naming conventions that aren't documented together and aren't consistent across the API.
Sharp Edge: EVP_CIPHER_CTX Reuse
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, key, iv);
EVP_EncryptUpdate(ctx, out, &outlen, in, inlen);
EVP_EncryptFinal_ex(ctx, out + outlen, &tmplen);
// DANGEROUS: Reusing ctx without reset
EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv2); // New IV only
// Some state from previous encryption may persist!The Problem: Context reuse rules are complex and vary by cipher mode.
Python's pickle
Sharp Edge: Arbitrary Code Execution by Design
import pickle
# DANGEROUS: Deserializes arbitrary Python objects
data = pickle.loads(untrusted_input)
# Attacker sends:
# b"cos\nsystem\n(S'rm -rf /'\ntR."
# Result: Executes shell commandThe Problem: pickle is not a data format—it's a code execution format. There is no safe way to unpickle untrusted data, but:
The function looks like a data parser
The name suggests food preservation, not danger
Many developers don't realize the risk
Mitigation: Use json for data. If you need pickle, use hmac to authenticate before unpickling (but even then, prefer safer formats).
YAML Libraries
Sharp Edge: Code Execution via Tags
import yaml
# DANGEROUS: yaml.load() executes arbitrary code
data = yaml.load(untrusted_input)
# Attacker sends:
# !!python/object/apply:os.system ['rm -rf /']The Problem: YAML's tag system allows arbitrary object instantiation. The "safe" loader is:
data = yaml.safe_load(untrusted_input) # Safe
data = yaml.load(untrusted_input, Loader=yaml.SafeLoader) # Also safeBut the dangerous version is the obvious one (yaml.load()).
PHP's strcmp for Password Comparison
Sharp Edge: Type Juggling Bypass
// DANGEROUS: Type juggling attack
if (strcmp($_POST['password'], $stored_password) == 0) {
authenticate();
}
// Attacker sends: password[]=anything
// strcmp(array, string) returns NULL
// NULL == 0 is TRUE in PHP!The Problem:
strcmpreturnsNULLon type error, not-1or1PHP's
==operator coercesNULLto0NULL == 0evaluates toTRUEAuthentication bypassed
Fix:
if (hash_equals($stored_hash, hash('sha256', $_POST['password']))) {
// Use hash_equals for timing-safe comparison
// AND proper password hashing (not shown)
}Analysis Template
When examining a library for sharp edges:
Input → Expected Output
| Input | Expected | Actual | Vulnerability |
|---|---|---|---|
verify_ssl=false | Clear warning | Silent acceptance | Config cliff |
password="" | Rejection | Login success | Empty bypass |
algorithm="none" | Error | Signature skipped | Downgrade |
timeout=-1 | Error | Infinite timeout | Magic value |
Library Comparison
| Feature | Dangerous Library | Safer Alternative |
|---|---|---|
| Bignum crypto | GMP | libsodium, OpenSSL BIGNUM |
| TLS | Raw OpenSSL | Higher-level wrappers |
| Serialization | pickle, YAML | JSON, protobuf |
| Password compare | strcmp | hash_equals, secrets.compare_digest |
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Declares allowed tools, Needs Python
Security
What our scanner noticed· Medium risk
- References to credential files
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Trail of Bits
- Publisher
- Trail of Bits (Official)
- Source
- trailofbits/skills · plugins/sharp-edges/skills/sharp-edges · commit e4dd0bb
- Licence
- Creative Commons Attribution-ShareAlike 4.0 International (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Trail of Bits.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download sharp-edges.zip