Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat(redact): close crypto-suffix identifier + webhook-URL gaps - #79

Open
swarit-stepsecurity wants to merge 2 commits into
step-security:mainfrom
swarit-stepsecurity:swarit/chore/redact-gaps
Open

swarit-stepsecurity wants to merge 2 commits into
step-security:mainfrom
swarit-stepsecurity:swarit/chore/redact-gaps

Conversation

@swarit-stepsecurity

Copy link
Copy Markdown
Member

Two narrow extensions to the redactor, motivated by a stress-test audit:

  1. Identifiers that contain a credential word but don't end on it (passwordHash, apiKeyDigest, accessTokenHmac, ...) slipped past secret_assignment because the existing rule anchored on the credential word ending the identifier. New rule secret_assignment_crypto_suffix matches the same prefix shape with a tight allowed-suffix list (HASH/HASHED/DIGEST/HMAC/ CIPHER/ENCRYPTED/SIGNATURE/SALT/SALTED). The suffix list is intentionally narrow so non-credential names like passwordless, tokenize, secretary, and tokenization_enabled stay non-redacted (covered by TestStringPreservesNonCredentialNeighbors).

  2. Webhook URLs carry their auth in the path; the URL itself is credential-grade. Added three rules: - slack_webhook_url: hooks.slack.com/{services,workflows}/...

    • discord_webhook_url: discord.com/api/webhooks//
    • teams_webhook_url: *.webhook.office.com / outlook.office.com

Tests cover both directions — the new shapes are redacted, and the adjacent-but-non-credential shapes stay intact.

What does this PR do?

Type of change

  • Bug fix
  • Enhancement
  • Documentation

Testing

  • Tested on macOS (version: ___)
  • Binary runs without errors: ./stepsecurity-dev-machine-guard --verbose
  • JSON output is valid: ./stepsecurity-dev-machine-guard --json | python3 -m json.tool
  • No secrets or credentials included
  • Lint passes: make lint
  • Tests pass: make test

Related Issues

Two narrow extensions to the redactor, motivated by a stress-test
audit:

1. Identifiers that *contain* a credential word but don't end on it
   (passwordHash, apiKeyDigest, accessTokenHmac, ...) slipped past
   secret_assignment because the existing rule anchored on the
   credential word ending the identifier. New rule
   `secret_assignment_crypto_suffix` matches the same prefix shape
   with a tight allowed-suffix list (HASH/HASHED/DIGEST/HMAC/
   CIPHER/ENCRYPTED/SIGNATURE/SALT/SALTED). The suffix list is
   intentionally narrow so non-credential names like `passwordless`,
   `tokenize`, `secretary`, and `tokenization_enabled` stay
   non-redacted (covered by TestStringPreservesNonCredentialNeighbors).

2. Webhook URLs carry their auth in the path; the URL itself is
   credential-grade. Added three rules:
     - slack_webhook_url:  hooks.slack.com/{services,workflows}/...
     - discord_webhook_url: discord.com/api/webhooks/<id>/<token>
     - teams_webhook_url:  *.webhook.office.com / outlook.office.com

Tests cover both directions — the new shapes are redacted, and the
adjacent-but-non-credential shapes stay intact.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical redaction gaps still expose secrets in quoted password-hash values, webhook tokens ending in hyphens, and webhook URLs with mixed-case schemes or hostnames.

3 open issues
What changed in this PR

This PR extends the AI-agent redactor to cover crypto-suffixed credential identifiers and webhook URLs whose paths contain authentication secrets.

Changes:

  • Adds a narrow suffix rule for identifiers such as passwordHash and apiKeyDigest.
  • Adds webhook URL redaction for Slack, Discord, and Microsoft Teams.
  • Adds tests for the new credential shapes and preservation of similar non-secret identifiers.
File Description
internal/​aiagents/​redact/​redact.go Adds crypto-suffix assignment and webhook URL rules.
internal/​aiagents/​redact/​redact_test.go Adds redaction tests and non-credential false-positive guards.

Review effort: Balanced

// HMAC is still credential-grade — leaking either feeds offline attacks.
{
name: "secret_assignment_crypto_suffix",
re: regexp.MustCompile(`(?i)\b([A-Z0-9_]*(?:PASSWORD|PASSWD|SECRET|TOKEN|API[_-]?KEY|ACCESS[_-]?KEY|PRIVATE[_-]?KEY)_?(?:HASH(?:ED|ES)?|DIGEST|HMAC|CIPHER|ENCRYPTED|SIGNATURES?|SALT(?:ED)?))\s*[:=]\s*("?)([^\s"'#]+)`),
// Covers discord.com, discordapp.com, and the canary/ptb subdomains.
{
name: "discord_webhook_url",
re: regexp.MustCompile(`\bhttps?://(?:ptb\.|canary\.)?discord(?:app)?\.com/api/(?:v\d+/)?webhooks/\d+/[A-Za-z0-9_\-]{60,}\b`),
Comment on lines +204 to +218
re: regexp.MustCompile(`\bhttps://hooks\.slack\.com/(?:services|workflows)/[A-Za-z0-9_/\-]+`),
},
// Discord webhook URLs. Token is the last path segment (≥60 chars).
// Covers discord.com, discordapp.com, and the canary/ptb subdomains.
{
name: "discord_webhook_url",
re: regexp.MustCompile(`\bhttps?://(?:ptb\.|canary\.)?discord(?:app)?\.com/api/(?:v\d+/)?webhooks/\d+/[A-Za-z0-9_\-]{60,}\b`),
},
// Microsoft Teams / Power Automate incoming-webhook URLs. Several
// tenant-specific subdomain shapes (<tenant>.webhook.office.com,
// outlook.office.com); the path segments past /webhook/ carry the
// rotating secret.
{
name: "teams_webhook_url",
re: regexp.MustCompile(`\bhttps://(?:[a-z0-9-]+\.)?(?:webhook\.office|outlook\.office)\.com/(?:webhook(?:b2)?|services/[^/\s]+/IncomingWebhook)/[A-Za-z0-9@/_\-]+\b`),

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants