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

Parameter manipulation vulnerability #74

Open
vanFrZy opened this issue Jun 1, 2023 · 0 comments
Open

Parameter manipulation vulnerability #74

vanFrZy opened this issue Jun 1, 2023 · 0 comments

Comments

@vanFrZy
Copy link

vanFrZy commented Jun 1, 2023

In the following code snippet, the parameter quantity is unchecked, meaning an attacker can inject a negative quantity into the request. This results in the cart being updated with a negative value which can be seen in the picture below.

  const handleAddToCart = async (productId, quantity) => {
    const item = await commerce.cart.add(productId, quantity);
    setCart(item.cart);
  };

image

A simple fix could be

  const handleAddToCart = async (productId, quantity) => {
    if (quantity > 0) {
        const item = await commerce.cart.add(productId, quantity);
        setCart(item.cart);
    }
    else { 
         // throw some error
      }
  };
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

No branches or pull requests

1 participant