Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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 a SecretString: it must be printed to its owner and stored. Key's Debug prints Key([REDACTED]); a type that holds a key as a String gets a redacting Debug. 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 a key field 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 through torrust_tracker_axum_server::request_log::redact_uri (and RedactedMakeSpan for the span), which replaces them with ***. Never log request.uri() directly.
  • The admin token goes in the Authorization: Bearer header, 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 reqwest error holds the URL, so wrap it with without_url(); a figment error echoes a value of the wrong type, so a new secret option must be added to SECRET_OPTIONS in packages/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 with databases::error::Error::from_statement_that_binds_a_secret.
  • Tests assert the absence of a unique test secret and never print it (tracker-core's assert_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 Display or Debug implementations
  • 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

Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить handle-secrets с