Fix/370 validate payload length#420
Open
Dami24-hub wants to merge 2 commits into
Open
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.