Skip to content

Secures telemetry health checks against information leakage and spam - #563

Merged
Mac-5 merged 5 commits into
Synapse-bridgez:mainfrom
Almikefred:main
May 31, 2026
Merged

Secures telemetry health checks against information leakage and spam#563
Mac-5 merged 5 commits into
Synapse-bridgez:mainfrom
Almikefred:main

Conversation

@Almikefred

Copy link
Copy Markdown
Contributor

Summary

Secures telemetry health checks against information leakage and spam, optimizes payment pagination to avoid full-table loads, optimizes telemetry metrics collection by reusing instruments
and preventing label cardinality explosion, and adds consistent pagination to all API list endpoints.

Changes

  • src/telemetry/health_checks.rs — secure health check manager with input validation, response redaction, and 5-second caching guard
  • src/payments/pagination.rs — pagination manager with 30-second count caching; enforces max page size (100); prevents unbounded queries
  • src/telemetry/metrics_optimization.rs — MetricsInstruments initialized once at startup; CardinalityLimiter bounds label sets; background export pattern documented
  • src/handlers/pagination.rs — PaginationQuery, PaginationHelper, and PaginatedListResponse envelope; validates page >= 1, page_size >= 1, page_size <= 100; returns 400 on invalid params

Testing

  • Health checks: valid check passes, sensitive values absent from response, rapid calls return cached result within 5s window, invalid inputs rejected
  • Payments pagination: correct first/subsequent pages via offset/limit, limit enforced and capped, empty result handled gracefully, count cached on repeat calls
  • Metrics: instruments verified not re-created on repeated calls, cardinality limiter rejects beyond max unique values, background export spawns without error
  • API pagination: default pagination returns page 1 with page_size 20, explicit params honored, over-limit page_size rejected with 400, page beyond total returns empty data with correct
    total, invalid params return 400

Closes #505
Closes #506
Closes #507
Closes #508

@drips-wave

drips-wave Bot commented May 31, 2026

Copy link
Copy Markdown

@Almikefred Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Implements secure health check logic with input validation, response redaction,
and call-frequency caching to prevent spam and information leakage.

- Add HealthCheckManager with caching and rate limiting (5-second cache window)
- Validate health check request parameters (reject empty/malformed input)
- Redact sensitive values from responses (no credentials/endpoints/internal state)
- Add comprehensive tests covering valid checks, cached results, and invalid inputs
- Add doc comments describing security invariants
Optimizes pagination logic with count caching and proper data layer delegation.

- Add PaginationManager with TTL-based total count caching (30-second default)
- Enforce maximum page size (100 records) to prevent unbounded queries
- Push pagination parameters to data access layer via offset/limit
- Implement cached count that avoids repeated count queries on subsequent pages
- Add comprehensive tests covering first/subsequent pages, limits, and caching
Optimizes metrics collection by initializing instruments once at startup,
moving export off the hot path, and bounding label cardinality.

- Initialize MetricsInstruments once at startup and reuse references (eliminates per-request allocation)
- Add CardinalityLimiter to bound high-cardinality label sets and prevent metrics explosion
- Implement background_metrics_export function to move metric export off hot path
- Add inline comments explaining performance rationale for each optimization
- Add tests verifying instruments are not re-created and cardinality is bounded
Adds consistent pagination support to all list-returning API endpoints with a
standard response envelope and input validation.

- Add PaginationQuery with page and page_size parameters (defaults: page=1, page_size=20)
- Enforce maximum page size (100 records) to prevent unbounded queries
- Validate pagination params and return 400 on invalid input (page < 1, page_size < 1, page_size > max)
- Implement PaginatedListResponse envelope with data/total/page/page_size
- Add PaginationHelper for offset/limit calculation and total page computation
- Return empty data array with correct total when page is beyond available data
- Add comprehensive tests covering defaults, explicit params, over-limit rejection, and boundary cases
@Mac-5
Mac-5 merged commit e6ff9cd into Synapse-bridgez:main May 31, 2026
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.

Implement Pagination in API Optimize Metrics Collection in Telemetry Optimize Pagination in Payments Secure Health Checks in Telemetry

2 participants