Fix: Harden API error handling, SQS retries, IAM permissions, and adaptor integrity - #2
Open
mozluk wants to merge 1 commit into
Open
Fix: Harden API error handling, SQS retries, IAM permissions, and adaptor integrity#2mozluk wants to merge 1 commit into
mozluk wants to merge 1 commit into
Conversation
…ptor integrity
### Description
This PR addresses critical backend, infrastructure, and financial-data integrity defects identified in the `yield-server` repository during the workspace-wide audit[cite: 34].
### Key Changes
* **Async Error Handling & Observability (`src/utils/asyncHandler.js`, `src/api/app.js`, `src/queries/*.js`):**
* Added a shared `asyncHandler` wrapper to ensure Express 4 routes properly forward rejected async promises to the centralized error middleware[cite: 34].
* Replaced silent `return new AppError` paths with explicit `throw` statements across controllers, query helpers, and triggers[cite: 34]. Invalid configuration UUID requests now return explicit HTTP 400 responses[cite: 34].
* Replaced the unsafe `res.render()` error handler (which lacked a view engine) with safe JSON responses that do not leak internal details[cite: 34]. Redis cache reads/writes now handle failures gracefully, log context, and treat Redis as optional when `REDIS_URL` is absent[cite: 34].
* **SQS & Scheduled Task Reliability (`src/handlers/triggerEntrypoint.js`, `src/handlers/triggerAdaptor.js`, `serverless.yml`):**
* Scheduled invocations no longer swallow queue-production failures; they now rethrow explicitly[cite: 34].
* SQS handlers now properly return `batchItemFailures` and enable `ReportBatchItemFailures`, ensuring failed records are isolated and retried without replaying successful ones[cite: 34].
* **Infrastructure Hardening & IAM (`serverless.yml`):**
* Removed overly broad wildcard permissions (`Resource: '*'`) for S3 (`s3:*Object*`, bucket listing) and SQS (`sqs:SendMessage`)[cite: 34]. The Lambda role is now strictly scoped to the generated CloudFormation bucket, the shared data bucket, and the generated adapter queue ARN[cite: 34].
* **Secrets Management (`src/adaptors/mars-lend/index.js`, `env.js`, `serverless.yml`):**
* Removed the hardcoded `x-apikey` credential from the Mars request URL[cite: 34]. The adaptor now securely reads `MARS_API_KEY` from the environment, URL-encodes it, and safely omits the query parameter when unconfigured[cite: 34].
* **Financial-Data Integrity & Fallbacks (`src/adaptors/enclabs/index.js`, `src/adaptors/merkl/index.js`, etc.):**
* Fixed critical fallback corruption in the `enclabs` adaptor where failing RPC calls previously substituted a cToken address or forced 18 decimals, producing materially misleading TVL and borrow metrics[cite: 34]. Required underlying-token and decimal calls now skip the affected market with structured warnings, and optional LTV data is omitted rather than forced to zero[cite: 34].
* Removed silent empty `catch` blocks in `merkl`, `berapaw`, `ichi`, `mezo`, `mystic-finance`, and `upshift` adaptors, replacing them with contextual diagnostic logs[cite: 34].
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.
Description
This PR addresses critical backend, infrastructure, and financial-data integrity defects identified in the
yield-serverrepository during the workspace-wide audit[cite: 34].Key Changes
src/utils/asyncHandler.js,src/api/app.js,src/queries/*.js):asyncHandlerwrapper to ensure Express 4 routes properly forward rejected async promises to the centralized error middleware[cite: 34].return new AppErrorpaths with explicitthrowstatements across controllers, query helpers, and triggers[cite: 34]. Invalid configuration UUID requests now return explicit HTTP 400 responses[cite: 34].res.render()error handler (which lacked a view engine) with safe JSON responses that do not leak internal details[cite: 34]. Redis cache reads/writes now handle failures gracefully, log context, and treat Redis as optional whenREDIS_URLis absent[cite: 34].src/handlers/triggerEntrypoint.js,src/handlers/triggerAdaptor.js,serverless.yml):batchItemFailuresand enableReportBatchItemFailures, ensuring failed records are isolated and retried without replaying successful ones[cite: 34].serverless.yml):Resource: '*') for S3 (s3:*Object*, bucket listing) and SQS (sqs:SendMessage)[cite: 34]. The Lambda role is now strictly scoped to the generated CloudFormation bucket, the shared data bucket, and the generated adapter queue ARN[cite: 34].src/adaptors/mars-lend/index.js,env.js,serverless.yml):x-apikeycredential from the Mars request URL[cite: 34]. The adaptor now securely readsMARS_API_KEYfrom the environment, URL-encodes it, and safely omits the query parameter when unconfigured[cite: 34].src/adaptors/enclabs/index.js,src/adaptors/merkl/index.js, etc.):enclabsadaptor where failing RPC calls previously substituted a cToken address or forced 18 decimals, producing materially misleading TVL and borrow metrics[cite: 34]. Required underlying-token and decimal calls now skip the affected market with structured warnings, and optional LTV data is omitted rather than forced to zero[cite: 34].catchblocks inmerkl,berapaw,ichi,mezo,mystic-finance, andupshiftadaptors, replacing them with contextual diagnostic logs[cite: 34].