Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update server/routes/api/checkout.js with issue #963 from AppSec Hack…
… Pod Key Improvements to post req create-checkout-session: 1. Input Validation with Joi: Ensures the incoming data (like donation, user, and letter) is valid before processing. * donation: Must be a positive number. * user: Must be a valid email. * letter: Has a character limit to prevent overflows. 2. Origin Validation: Validates the origin header against a list of trusted domains. Requests from untrusted origins are rejected with a 403 Forbidden response. **This must be hardcoded, added in config files, or DB** (Line 55) 3. Error Handling: Catches validation errors and any unexpected errors to provide meaningful responses to the client while logging them for debugging. 4. Secure Logging: Avoids logging sensitive data. Logs only the origin if it’s valid, and logs warnings for untrusted origins. Key Improvements to sessionSchema for least privilege: 1. Donation limit: The donation is capped at a reasonable value (max(10000)), reducing the risk of abuse from excessive amounts. 2. Scoped user object: We are limiting the user field to just an email address (instead of allowing any arbitrary data structure). This limits the amount of user data passed into the session. 3. Error messages: Explicit error messages are provided to make validation clearer for users without revealing too much information. 4. Letter size: The max length for the letter is reduced from 500 to 300 characters, limiting the potential impact of large data inputs. 5. Strict schema: By adding .unknown(false), we ensure that no extraneous data is accepted, enforcing stricter input control for least privilege.
- Loading branch information