Skip to content
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

Update /checkout.js with issue #963 from AppSec Hack Pod #972

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DanielArevalo059
Copy link

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.
  1. 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)

  2. Error Handling: Catches validation errors and any unexpected errors to provide meaningful responses to the client while logging them for debugging.

  3. 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.

… 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.
@DanielArevalo059 DanielArevalo059 linked an issue Oct 16, 2024 that may be closed by this pull request
2 tasks
Copy link

emote

Copy link

Hello there, thanks for opening your first Pull Request. Someone will review it soon.

Ran Prettier linter and removed some lines of code that prematurely returned from the function, making code below it unreachable. Previously lines ~86 - 90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Function] Secure and sanitize API inputs
1 participant