Skip to content

fix: rate limit factory validation, dynamic Retry-After, fractional refill test, schema accuracy#107

Merged
intel352 merged 2 commits intofix/auth-rate-limitingfrom
copilot/sub-pr-101
Feb 23, 2026
Merged

fix: rate limit factory validation, dynamic Retry-After, fractional refill test, schema accuracy#107
intel352 merged 2 commits intofix/auth-rate-limitingfrom
copilot/sub-pr-101

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

Four issues identified in review of the per-IP rate limiting PR:

  • rateLimitMiddlewareFactory silently accepted zero/negative config values, causing permanent rate-limiting or immediate rejection
  • Retry-After was hardcoded to 60 regardless of the configured rate (wrong by orders of magnitude for hourly limiters)
  • burstSize schema description was semantically incorrect
  • No test exercising fractional token refill over time

Changes

plugins/http/modules.go

  • Guard all numeric config reads (requestsPerHour, requestsPerMinute, burstSize) with > 0; invalid values fall back to defaults

module/http_middleware.go

  • Compute Retry-After dynamically: ceil(60 / ratePerMinute) seconds
    • 5 req/hour → 720 s; 10 req/min → 6 s; 60 req/min → 1 s
  • Added math, strconv imports

plugins/http/schemas.go

  • burstSize description: "Maximum number of tokens in the bucket; determines how many requests can burst when the bucket is full"

module/http_middleware_test.go

  • TestNewRateLimitMiddlewareWithHourlyRate_FractionalRefill: exhausts burst, sleeps exactly one token-refill period, asserts exactly one additional request passes and the next is rejected
  • Updated TestRateLimitMiddleware_RetryAfterHeader: expected value "60""1" (correct for 60 req/min)

plugins/http/plugin_test.go

  • TestRateLimitMiddlewareFactory_InvalidValues: zero requestsPerHour, negative requestsPerMinute, zero burstSize all fall back to defaults without panicking

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…al refill test, fix schema description

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copilot AI changed the title [WIP] Add strict per-IP rate limiting to auth endpoints fix: rate limit factory validation, dynamic Retry-After, fractional refill test, schema accuracy Feb 23, 2026
Copilot AI requested a review from intel352 February 23, 2026 05:34
@intel352 intel352 marked this pull request as ready for review February 23, 2026 06:20
@intel352 intel352 merged commit b3fedf3 into fix/auth-rate-limiting Feb 23, 2026
@intel352 intel352 deleted the copilot/sub-pr-101 branch February 23, 2026 06:21
intel352 added a commit that referenced this pull request Feb 23, 2026
* security: add algorithm pinning tests for JWT confusion attacks (closes #95)

Verified that all JWT validation paths in JWTAuthModule already enforce
HS256 via both type assertion (*jwt.SigningMethodHMAC) and explicit
algorithm check (token.Method.Alg() != jwt.SigningMethodHS256.Alg()).

Added tests to module/jwt_auth_test.go that explicitly confirm tokens
signed with HS384 or HS512 are rejected by:
- Authenticate() — the AuthProvider interface method
- handleRefresh via Handle() — the /auth/refresh endpoint
- extractUserFromRequest via Handle() — all protected endpoints

The api package (middleware.go, auth_handler.go) already had equivalent
algorithm rejection tests in auth_handler_test.go.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: document 10+ undocumented module types in DOCUMENTATION.md (closes #66)

Adds detailed documentation for audit logging, license.validator,
platform.provider/resource/context, observability.otel, step.jq, AI
pipeline steps (ai_complete, ai_classify, ai_extract), CI/CD steps
(docker_build, docker_push, docker_run, scan_sast, scan_container,
scan_deps, artifact_push, artifact_pull), and the admincore plugin.
Each entry includes config field tables with types and defaults, plus
a minimal YAML example. Summary tables in the module type index are
also updated with the new Infrastructure and CI/CD Step categories.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* security: add strict per-IP rate limiting to auth endpoints (closes #94)

- Add dedicated rate-limit middleware modules for login (10/min) and
  register (5/hour) in admin/config.yaml, replacing the shared global
  limiter that allowed 120 req/min on sensitive auth endpoints
- Extend RateLimitMiddleware to support fractional rates via float64
  token buckets, enabling hourly rate configs without precision loss
- Add NewRateLimitMiddlewareWithHourlyRate constructor and factory
  support for requestsPerHour config key
- Add requestsPerHour field to the http.middleware.ratelimit schema
- Add tests for hourly rate middleware and per-hour factory config

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: rate limit factory validation, dynamic Retry-After, fractional refill test, schema accuracy (#107)

* Initial plan

* fix: validate rate limit config values, dynamic Retry-After, fractional refill test, fix schema description

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
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