Skip to content

Warn when METRICS_TOKEN is shorter than the 32-char minimum - #1193

Merged
helpcodeai merged 2 commits into
HelpCode-ai:mainfrom
rangarajan19:fix/metrics-token-length-warning
Oct 22, 2026
Merged

helpcodeai merged 2 commits into
HelpCode-ai:mainfrom
rangarajan19:fix/metrics-token-length-warning

Conversation

@rangarajan19

Copy link
Copy Markdown
Contributor

Summary

Small follow-up from @helpcodeai's review on #1131 (the opt-in /metrics endpoint): other secrets in secrets.util.ts (JWT_SECRET, ENCRYPTION_KEY) already enforce a 32-char minimum via MIN_SECRET_LENGTH. METRICS_TOKEN didn't, so this adds a one-time warning (not a hard failure — metrics is opt-in, so a short token is still better than none) when it's set below that bar.

From the review:

Other secrets in secrets.util.ts must be at least 32 characters. A warning when METRICS_TOKEN is shorter would be consistent. Happy to take that as a follow-up rather than hold this PR.

Changes

  • Export MIN_SECRET_LENGTH from secrets.util.ts so metrics.ts reuses the same threshold instead of a hardcoded number.
  • metrics.ts: log a one-time warning when METRICS_TOKEN.length < MIN_SECRET_LENGTH; the listener still starts.
  • metrics.spec.ts: two new tests (warns once + still serves metrics on a short token; silent on a token that meets the minimum). Bumped the suite's DEFAULT_TOKEN to 32+ chars so existing tests aren't tripped by the new warning.
  • docs/operations/observability.md: noted the 32-char recommendation and warning behavior in the METRICS_TOKEN row.

Type

  • Bug fix
  • New feature
  • Documentation
  • Refactoring
  • Performance improvement
  • Other (describe below)

Testing

  • Added/updated unit tests
  • Tested manually (describe steps below)
  • No tests needed (explain why)

Ran from packages/backend, after npx prisma generate (needed to pick up the unrelated schema changes merged into main since #1131):

npx tsc --noEmit -p tsconfig.json
npx jest src/common/metrics src/common/secrets --silent
npx jest src/connectors src/mcp-server src/health src/common --maxWorkers=2 --silent
  • tsc --noEmit: clean.
  • metrics suite: 14/14 passed (12 existing + 2 new).
  • Full backend suite: 2468 passed, 0 failed, 15 skipped (pre-existing, env-gated live/integration specs, unrelated to this change).

Checklist

  • My code follows the existing code style
  • I have tested my changes locally
  • I have updated documentation (if applicable)
  • All existing tests pass (npm test)
  • This PR has a descriptive title

Related Issues

Follow-up from the review on #1131 (no separate issue was filed for this one — it was raised and explicitly offered as "up for grabs" directly in that PR's review).

Other secrets in secrets.util.ts (JWT_SECRET, ENCRYPTION_KEY) already
enforce MIN_SECRET_LENGTH. METRICS_TOKEN is opt-in, so a short value
only logs a one-time warning instead of blocking the listener.

Export MIN_SECRET_LENGTH from secrets.util.ts so metrics.ts reuses the
same threshold instead of a hardcoded number.
@rangarajan19

Copy link
Copy Markdown
Contributor Author

@helpcodeai PR is up for the METRICS_TOKEN length warning you mentioned on #1131.

Please let me know if there's anything off or needs fixing — happy to get to it right away.

@helpcodeai helpcodeai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @rangarajan19, this is what I had in mind, and reusing MIN_SECRET_LENGTH instead of a second hardcoded 32 is nicer. The branch is behind main, I'll update it and merge once CI is green.

@helpcodeai
helpcodeai enabled auto-merge (squash) October 22, 2026 09:48
@helpcodeai
helpcodeai merged commit 4114840 into HelpCode-ai:main Oct 22, 2026
14 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 22, 2026
@helpcodeai

Copy link
Copy Markdown
Contributor

Merged and shipped in v0.45.3, thanks again @rangarajan19!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants