Skip to content

Conversation

@myProjectsRavi
Copy link
Owner

No description provided.

…ation and workflows to reflect changes in API key management and deployment processes.
…cture; add rate limiting and dead letter queue tables
- Added `getUsdaFoodSearch` and `getUsdaFoodDetails` functions to improve food search capabilities with error handling and logging.
- Implemented ranking logic in `rankFoodSuggestions` to prioritize high-quality data types and boost preferred preparation keywords.
- Refactored nutrient parsing logic to streamline nutrient mapping from USDA API responses.
- Updated middleware to log normalized API keys for better debugging.
- Enhanced cache service to use versioned keys and improved logging for cache hits and misses.
- Added comprehensive tests for food search handlers and food suggestion utilities to ensure robustness and accuracy.
…terface and update references in getGramWeight function
…ult and update API response structure for improved portion tracking
…lculatedAmount and calculatedNutrients fields
…d optimizing resource usage

- Mitigate "Free Lunch" loophole by enforcing credit deductions for natural language searches and implementing item limits.
- Improve D1 write-lock contention by removing synchronous DELETE operations and scheduling cleanup tasks.
- Introduce lazy loading for heavy libraries to reduce cold start times and CPU consumption.
- Implement substring and word matching boosts in confidence calculations to improve search accuracy.
- Refactor natural language search handler to ensure proper credit deduction and item truncation.
- Optimize rate limiting by ensuring synchronous inserts into rate limit logs to maintain accurate usage tracking.
- Enhance D1 local service to retrieve food data more efficiently by using JSON blobs.
…ance revenue protection and prevent resource exploitation
- Implemented character length capping in naturalLanguageSearch to prevent ingredient stuffing attacks based on user tier.
- Introduced a manual string tokenizer in parseHandler to mitigate ReDoS vulnerabilities, replacing complex regex with O(N) performance.
- Optimized d1BulkDataService to exclusively use FTS5 indexed search, eliminating fallback LIKE queries to reduce row reads and enhance performance.
- Enhanced hotCache service with hardcoded seeds for top foods, significantly reducing cold start latency and improving access times.
- Added a global semaphore in usda service to limit USDA API calls, preventing rate limit exhaustion and potential key bans.
… size limits and refined input validation across multiple schemas
…ndations for improved security and cost management

fix(logging): Enhance logging middleware to include rate limit headers and remove sensitive tier information

feat(rateLimiter): Add rate limit information to request context for better user transparency and experience

fix(securityHeaders): Remove X-API-Tier header to prevent tier enumeration attacks and enhance security

feat(apiKeyService): Implement Cache API checkpoint system for batching credit deductions, reducing D1 writes significantly

fix(d1BulkDataService): Introduce FTS5 query compiler to neutralize CPU bomb attacks and sanitize user input

feat(usdaBatch): Optimize batch timing for USDA API requests to improve response times and user experience
…imize D1 write usage and enhance cache performance
…rt 18

- Implemented statistical sampling for hot cache updates to reduce write volume and prevent "Hot Cache" write stampede.
- Introduced a hybrid wallet system for credit deductions to mitigate double-spend attacks across distributed Cloudflare Workers.
- Enhanced FTS query compiler to prevent D1 row read explosion by enforcing strict token limits and query shaping.
- Added cache poisoning protection with size limits, entropy checks, and adaptive TTL for cache entries.
- Replaced regex-based parsing with a deterministic lexical scanner to eliminate ReDoS vulnerabilities.
- Isolated circuit breaker implementation per API key to prevent noisy neighbor attacks and improve availability.
…y handling to enhance performance and mitigate vulnerabilities
…uality responses are stored, preventing cache pollution and optimizing storage usage
… address audit report vulnerabilities with improved caching strategies and performance optimizations.
…uth failures to enhance security

feat(apiKeyService): Add low balance guarantee for D1 sync to prevent revenue loss and ensure accurate credit deductions

fix(naturalLanguageSearchHandler): Replace ctx.waitUntil with safeBackgroundTask to prevent isolate crashes during cache operations
… kvCacheService

- Introduced a daily write budget of 800 KV writes to prevent exceeding the Cloudflare Free Tier limit.
- Added a bypass option for critical paths and a viral item promotion mechanism based on access count.
- Enhanced cache poisoning protection with additional checks and adaptive TTL for low-confidence items.
- Implemented logging for budget status and write operations to facilitate monitoring and debugging.
- Updated the put method to enforce the new budget checks and record successful writes accordingly.
…ogic

- Introduced an adaptive gatekeeper for KV writes that dynamically adjusts the required access count based on budget consumption.
- Replaced static daily write limit checks with a formula that increases the access threshold as the budget is depleted, enhancing defense against potential abuse.
- Updated documentation to reflect changes in budget management strategy and the rationale behind the new adaptive approach.
- Improved logging for better monitoring of budget usage and threshold adjustments.
…background task failures

- Added hard limit of 5 to D1 queries to prevent pagination bomb attacks, reducing potential D1 reads by 96%.
- Replaced all instances of ctx.waitUntil with safeBackgroundTask in calculateHandler to isolate background task failures and prevent user-facing errors.
- Introduced safeBackgroundTask utility for safe execution of background tasks, ensuring errors are logged without impacting user experience.
- Updated security audit documentation to reflect changes and assess risk reduction.
… write efficiency and mitigate Distributed Amnesia vulnerability

- Replaced the existing adaptive threshold mechanism with a stateless approach using time and latency as proxies for cache write probability.
- Introduced latency tracking across various cache write operations to inform caching decisions based on request value.
- Updated KV cache service to utilize a deterministic hash for fairness across worker isolates, ensuring consistent cache behavior.
- Enhanced logging to provide insights into cache write decisions and their underlying metrics.
- Applied bypassWriteBudget flag for critical paths and scheduled warming tasks to prevent unnecessary budget consumption.
- Refactored related services and handlers to align with the new caching strategy, ensuring optimal performance and resource utilization.
…to enhance API resilience

- Introduced a global circuit breaker mechanism using KV to prevent overwhelming the USDA API during outages.
- Added FTS budget gate to limit the number of FTS queries based on time-decayed probability, reducing the risk of exceeding daily read limits.
- Implemented TTL jitter for cache entries to prevent simultaneous expirations, mitigating cache stampede risks.
- Enhanced negative cache management with multi-layer validation to prevent cache poisoning from random or malicious queries.
- Updated request deduplication logic to acknowledge its limitations in a distributed environment while still providing significant reduction in duplicate calls.
- Improved logging and error handling across services for better observability and debugging.
…t-circuit for RapidAPI requests to enhance billing protection and performance
… timing-safe secret verification and environment validation to prevent deployment amnesia
…tion for improved billing accuracy and revenue protection
…ling accuracy and prevent "Last Credit Gamble" vulnerability
…ntation of Hybrid Accounting and address potential vulnerabilities
…rming and ensure accurate receipt-based reversals
…ity and user experience by removing sensitive metadata
…austion attacks by validating credentials before processing requests
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