-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add generic batching utilities for API mutations #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces generic batching utilities to handle API mutations that have size limits (e.g., 100 employee compensations per request). The implementation provides a reusable useBatchedMutation hook that wraps TanStack Query mutations with automatic batching capabilities.
Key Changes:
- Adds
useBatchedMutationhook for automatic batch processing of large datasets - Implements core batching logic in
batchProcessor.tswith configurable batch sizes - Includes comprehensive test coverage for both the hook and helper utilities
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/hooks/useBatchedMutation.ts |
React hook providing batched mutation capabilities with loading state management |
src/hooks/useBatchedMutation.test.ts |
Test suite for the batched mutation hook covering batching, loading states, and error handling |
src/helpers/batchProcessor.ts |
Core utilities for splitting arrays into batches and sequential batch processing |
src/helpers/batchProcessor.test.ts |
Comprehensive tests for batch splitting and processing logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9426948 to
120247c
Compare
|
This pull request introduces or includes a batched-update capability via a useBatchedMutation hook and processBatches function that can send up to 100 payroll updates per request (though current UI components send one at a time). If the backend API (baseUpdatePayroll from @gusto/embedded-api/mod) does not validate batch size or consider batch item counts in rate limiting, this could allow business-logic abuse such as mass payroll modifications or bypassing single-update rate limits.
Business Logic Abuse via Batched Updates in
|
| Vulnerability | Business Logic Abuse via Batched Updates |
|---|---|
| Description | The useBatchedMutation hook allows for sending up to 100 payroll updates in a single request. While the current client-side implementation in PayrollConfiguration.tsx and PayrollEditEmployee.tsx only sends one item at a time, the underlying processBatches function and the useBatchedMutation hook are designed to handle batches of up to 100 items. The baseUpdatePayroll function, which is called by the batched mutation, originates from an external API (@gusto/embedded-api/mod). Without access to the backend implementation of this API, it is impossible to determine if adequate rate limiting or payload size validation is in place on the server-side to prevent abuse. If the backend does not properly validate the batch size or implement rate limiting that considers the number of items in a batch, an attacker could potentially bypass existing rate limits designed for single updates or perform mass modifications of payroll data more efficiently than with individual requests. |
embedded-react-sdk/src/components/Payroll/PayrollConfiguration/PayrollConfiguration.tsx
Lines 118 to 130 in 6172843
| const { mutateAsync: updatePayroll, isPending: isUpdatingPayroll } = useBatchedMutation( | |
| async (batch: PayrollUpdateEmployeeCompensations[]) => { | |
| const result = await baseUpdatePayroll({ | |
| request: { | |
| companyId, | |
| payrollId, | |
| payrollUpdate: { employeeCompensations: batch }, | |
| }, | |
| }) | |
| return result.payrollPrepared! | |
| }, | |
| { batchSize: 100 }, | |
| ) |
All finding details can be found in the DryRun Security Dashboard.
- Add useBatchedMutation hook with TanStack-style API - Add generic batchProcessor helpers (splitIntoBatches, processBatches) - Hook wraps any mutation to transparently handle API batch limits - Works by passing mutation function and calling with array - Comprehensive test coverage (23 tests) - Documentation with usage examples
feat: implement batching for payroll updates to support v2025-06-15 API changes - Update PayrollConfiguration and PayrollEditEmployee to use useBatchedMutation - Set batch size to 100 to align with API maximum for employee compensations - Simplify implementation by passing inline async functions to useBatchedMutation - Remove unnecessary useCallback wrappers as useBatchedMutation handles refs internally - Future-proofs components for bulk payroll update operations
956b60c to
6172843
Compare
Add Generic Batching for API Mutations
Problem
The API limits payroll updates to 100 employee compensations per request. We currently can't handle larger payrolls without manually implementing batching logic in each component.
Solution
New
useBatchedMutationhook - works exactly like TanStack Query mutations, but with automatic batching.How It Works
isPendingfor all batchesWhat's Included
src/hooks/useBatchedMutation.tssrc/helpers/batchProcessor.tsUse Anywhere
Works with any tanstack query mutation that needs batching: