handle-secrets
БесплатноБез исполняемых скриптовНе проверенKeep API tokens, passwords and other credentials in secrecy types, never a plain String; expose_secret only where needed. Use when handling secrets or…
от torrust★ 539 звёзд на GitHubОб этом скилле
Handling Sensitive Data (Secrets)
Core Rule
NEVER use plain String for sensitive data. Use the current stable
secrecy::SecretString type for string secrets to prevent accidental exposure.
// ❌ WRONG: secret leaked in Debug output
pub struct ApiConfig {
pub token: String,
}
println!("{config:?}"); // → ApiConfig { token: "secret_abc123" } — LEAKED!
// ✅ CORRECT: secret redacted in Debug
use secrecy::SecretString;
pub struct ApiConfig {
pub token: SecretString,
}
println!("{config:?}"); // → ApiConfig { token: SecretBox<str>([REDACTED]) }
Using the secrecy Crate
Add the dependency:
[dependencies]
secrecy = { version = "0.10", features = [ "serde" ] }
Enable serde only when a secret must be read from or written to a serialized
configuration format. This is an intentional opt-in: configuration-file syntax remains
unchanged while the Rust type becomes SecretString.
Basic usage:
use secrecy::{ExposeSecret, SecretString};
// Wrap the secret
let token = SecretString::from("my-api-token");
// Access the value only when truly needed (e.g., making the actual API call)
let token_str: &str = token.expose_secret();
What to Protect
Wrap with SecretString (or another appropriate direct secrecy type) when the value is:
- API tokens (REST API admin token, external service tokens)
- Passwords (database credentials, service accounts)
- Private keys or certificates
Secrets That Are Not Configuration
The peer authentication key, a REST API key and the admin token are secrets wherever they travel (see the amendment in the secrecy ADR).
- The peer key is
Key, not aSecretString: it must be printed to its owner and stored.Key'sDebugprintsKey([REDACTED]); a type that holds a key as aStringgets a redactingDebug. Print or serialize a key only where it is deliberately handed to its owner or persisted. - Errors never keep or print a secret, even a malformed one. State the length received or the
rule for its characters (
expected 32 characters, got 14), or that it is not registered or has expired. Do not add akeyfield to an error variant. - Secrets in URLs: the peer key is a path segment (
/announce/<key>,/scrape/<key>,/api/v1/key/<key>) and a token may be a?token=query value. Log a request URI only throughtorrust_tracker_axum_server::request_log::redact_uri(andRedactedMakeSpanfor the span), which replaces them with***. Never logrequest.uri()directly. - The admin token goes in the
Authorization: Bearerheader, in clients, scripts and documentation.?token=is still accepted by the server but it ends up in proxy and browser logs. Do not write it in an example. The header only keeps the token out of logged URLs (a proxy set to log headers still sees it); it does not protect it in transit, so do not call it safe without HTTPS. - Library errors that print the value they rejected: a
reqwesterror holds the URL, so wrap it withwithout_url(); afigmenterror echoes a value of the wrong type, so a new secret option must be added toSECRET_OPTIONSinpackages/configuration/src/secret_options.rs; a database server message can hold a written value (MySQL prints a duplicate key), so convert the error of a statement that binds a secret withdatabases::error::Error::from_statement_that_binds_a_secret. - Tests assert the absence of a unique test secret and never print it
(
tracker-core'sassert_holds_no_secret,test-helpers'capture_logs_while).
Rules for .expose_secret()
- Call as late as possible — only at the point where the value is required
- Never call in
log!,debug!,info!,warn!,error!macros - Never call in
DisplayorDebugimplementations - Never include in error messages that may be logged or shown to users
// ✅ Correct: called at last moment for HTTP header
let response = client
.get(url)
.header("Authorization", format!("Bearer {}", token.expose_secret()))
.send()
.await?;
// ❌ Wrong: exposed in log
tracing::debug!("Using token: {}", token.expose_secret());
Comparing Secrets
Never compare a secret with ==, !=, eq(), or Iterator::any over ==. Those may
exit at the first differing byte and leak, through timing, how many leading bytes were
correct. Use subtle::ConstantTimeEq on the byte slices and, when checking against several
candidates, evaluate all of them and OR the Choice results instead of stopping at the
first match:
use subtle::{Choice, ConstantTimeEq};
let provided = provided.as_bytes();
let matched = configured.iter().fold(Choice::from(0), |acc, secret| {
acc | secret.expose_secret().as_bytes().ct_eq(provided)
});
bool::from(matched)
subtle is already a workspace dependency (transitively via sqlx); adding it dir
Установить handle-secrets в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл handle-secrets?
Keep API tokens, passwords and other credentials in secrecy types, never a plain String; expose_secret only where needed. Use when handling secrets or sensitive configuration.
Как установить скилл handle-secrets?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл handle-secrets запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic