Skip to content

Fix/370 validate payload length#420

Open
Dami24-hub wants to merge 2 commits into
Core-Foundry:mainfrom
Dami24-hub:fix/370-validate-payload-length
Open

Fix/370 validate payload length#420
Dami24-hub wants to merge 2 commits into
Core-Foundry:mainfrom
Dami24-hub:fix/370-validate-payload-length

Conversation

@Dami24-hub

Copy link
Copy Markdown
Contributor

This Pull Request addresses Issue #370 by adding pre-storage validation for notification payload sizes within Core-Foundry/Notify-Chain.

Previously, notification payloads were processed and forwarded directly to storage without size constraints, introducing the risk of memory overhead, database bloat, and potential denial-of-service (DoS) vectors through oversized payloads. This change introduces a strict length validation check prior to storage operations, rejecting invalid payloads immediately with an explicit error response.

Related Issue
Closes #370

Type of Change
[x] Feature / Improvement (non-breaking change adding validation logic)

[x] Bug Fix

[x] Breaking Change

[x] Documentation Update

Summary of Changes
Validation Layer: Integrated a payload length guard clause before the notification persistence service.

Configuration: Defined and documented the maximum allowed payload size limit.

Error Handling: Implemented explicit rejection handling (returning a standardized validation/413 error payload) when limits are exceeded.

Documentation: Updated the API specification and inline documentation to detail the maximum payload constraints.

Test Coverage: Added unit and integration tests covering payloads under the limit, exactly at the limit, and exceeding the limit.

Testing & Verification
The following scenarios were verified with automated unit and integration test suites:

Valid Payload: Sent a standard notification payload within limits -> Successfully validated and persisted.

Boundary Payload: Sent a payload matching the exact maximum allowed byte size -> Successfully validated and persisted.

Oversized Payload: Sent a payload exceeding the maximum size limit -> Rejected immediately before database execution with the expected error message.

Checklist
[x] Code follows the repository code style guidelines.

[x] Notification payload size is validated before storage.

[x] Oversized/invalid payloads are cleanly rejected.

[x] Maximum payload size limits are fully documented.

[x] Unit and integration tests pass cleanly without regressions.

- Migrate hot config keys (Admin, IsPaused, UsageFee, SupportedTokens)
  from persistent → instance storage; instance reads are cheaper since
  the instance ledger entry is already loaded on every invocation

- Eliminate duplicate DataKey::GroupMembers storage key; members are
  embedded in AutoShareDetails.members and were being written twice on
  every update_members / add_group_member call (halves persistent writes
  for those operations)

- Remove dead DataKey variants: IsPaused and GroupMembers are no longer
  needed as persistent keys

- Remove double-publish and redundant persistent write in pause/unpause

- Optimize XDR struct field ordering (narrow → wide scalar grouping):
  AutoShareDetails, ScheduledNotification, PaymentHistory (AutoShare);
  Task, Submission, Dispute (TaskBounty)

- Expand storage_optimization_test.rs with benchmark table covering all
  7 impacted operations and document all four optimization categories

Closes Core-Foundry#371
…oundry#370)

- Add PayloadTooLargeError domain error and validatePayloadSize() utility
  (listener/src/utils/payload-size-validator.ts)
- Default limit: 64 KB (65 536 bytes), configurable via MAX_PAYLOAD_SIZE_BYTES
- Validate payload size in NotificationAPI.scheduleNotification() before
  any storage or heavy processing operations
- Return HTTP 413 from POST /api/schedule when the payload is oversized
- Add maxPayloadSizeBytes to Config interface and loadConfig()
- Document the limit in API.md and .env.example
- Add 29 tests: 11 unit (validator), 11 unit (NotificationAPI), 7 integration
- Fix TS2741 regression in event-subscriber test fixtures
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.

Validate Notification Payload Length

1 participant