agentleFS
discord-phpdiscord-php/DiscordPHP/.github/skills/discord-php-bot-security/SKILL.md

discord-php-bot-security

Skill1.1k starsChanged 35 days agoMITView on GitHub

Audit checklist for DiscordPHP bots and API libraries — stop the bot token leaking to third-party APIs or logs, keep secrets out of custom_ids and exception messages, use constant-time comparison and crypto-random for auth/CSRF/webhook flows, and don't log OAuth codes / full headers / PII. Use when reviewing an HTTP client, an error handler, an OAuth or webhook endpoint, or before publishing a repo.

  • Reads credentials

Trending

More talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 2 mentionsMar 2026: 0 mentionsApr 2026: 1 mentionMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 4 mentionsSep 2026: 13 mentionsOct 2026: 9 mentionsNov 2026: 1 mention
Dec 2025Jun 2026Nov 2026
Mentions a month of the discord-php/DiscordPHP repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about discord-php/DiscordPHP

The biggest 5 of 52 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 52

Talked about on GitHub and Bluesky (52 times).

On GitHub · 50

45 more on GitHub

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do not log full request/response bodies on error.

    line 30
  2. Very specific:

    Webhook signature: verify with hash_equals(), prefer X-Hub-Signature-256, and fail closed when the shared secret env var is unset (an unset …

    line 58
  3. Very specific:

    Redirect URIs: always validate the effective redirect_uri against an allow-list — a caller-supplied value must not bypass the check (open …

    line 61
  4. Very specific:

    Verify nothing sensitive is tracked: git ls-files | grep -iE '\.env|token|secret|\.pem|\.key|credential'.

    line 77
  5. Very specific:

    Never place personal data or tokens in URL query strings (they get logged by proxies and land in Referer).

    line 78

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

DiscordPHP Bot Security Skill

A concrete checklist built from real findings across DiscordPHP-MTG, DiscordPHP-NHA, DiscordPHP-Voice and Civilizationbot.

1. Never send the Discord bot token to a third party

The classic bug: an extension's Http client for api.example.com is constructed with 'Bot '.$this->token and adds Authorization: <token> to every request — so the Discord bot token is sent to an unrelated host on every call.

  • Extension HTTP clients for a third-party API should take an empty token and only set Authorization when a real value is present:
    $h = ['User-Agent' => $this->getUserAgent()];
    if ($this->token !== '')  $h['Authorization'] = $this->token;
    if ($this->apiKey !== null) $h['X-Api-Key'] = $this->apiKey;   // that API's own key
  • Drop Discord-only headers (X-Ratelimit-Precision) from non-Discord clients.
  • Override getUserAgent() to identify your library, not DiscordPHP-HTTP.

2. Keep tokens out of logs and exception messages

  • Do not log full request/response bodies on error. A FastAPI-style 422 body echoes the request back under input — for an auth'd POST that includes the token. Redact before logging and before putting it in an exception message:
    $body = preg_replace('/("(?:nha_)?token"\s*:\s*)"[^"]*"/i', '$1"***"', $body) ?? $body;
  • Manager/gateway code: log ['token' => '*****'], and give payload parts a __debugInfo() that redacts the token (see VoicePayload::__debugInfo()). Log identify with ['op' => $payload->op], not the whole payload.
  • Global error handlers that DM a technician: send file:line:function from debug_backtrace() (no ['args']). getTraceAsString() still inlines scalar args truncated to 15 chars — a token prefix can leak. Prefer the arg-free form.

3. Keep secrets out of custom_id

Component custom_ids are sent to Discord and visible in the client. Capture the agent/session token in the server-side listener closure, never in the id or a button label. (NHA's AgentObservation::toContainer($nha, $token) does this right — $token lives only in the $submit closure.)

4. OAuth2 / CSRF / webhooks

  • State / session ids: bin2hex(random_bytes(16)), never uniqid() (predictable microtime).
  • Compare with hash_equals(), not === / !== — HMAC signatures and CSRF state tokens. Reject empty/absent values up front; make the state single-use (delete it after a successful exchange).
  • Webhook signature: verify with hash_equals(), prefer X-Hub-Signature-256, and fail closed when the shared secret env var is unset (an unset secret makes hash_hmac key '' and every request "valid").
  • Redirect URIs: always validate the effective redirect_uri against an allow-list — a caller-supplied value must not bypass the check (open redirect / auth-code interception).
  • Don't log the OAuth authorization code (an exchangeable credential), the full request header set on a rejected request (a mistyped Authorization lands in the log), or contact-form email/message bodies (PII — send them to the private channel, not the log).
  • Raw curl in an OAuth path: set CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CONNECTTIMEOUT, CURLOPT_TIMEOUT, curl_close(), and null-check the result.

5. Repo hygiene

  • .gitignore must cover .env, .env.*, composer.lock (in these repos), /var/* (state files with tokens), and any bespoke secret file (token.php, /json, botlog.txt).
  • Verify nothing sensitive is tracked: git ls-files | grep -iE '\.env|token|secret|\.pem|\.key|credential'.
  • Never place personal data or tokens in URL query strings (they get logged by proxies and land in Referer).

Quick grep sweep

rg -n "addQuery\(\s*['\"](token|key|secret|password)" src/          # token in URL
rg -n "(debug|info|warn|error).*(token|Authorization|getBody|payload|->data\b)" src/
rg -n "!==|===" src/ | rg -i "hash_hmac|signature|hash_equals"      # non-constant-time
rg -n "uniqid\(" src/                                               # weak randomness

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.