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

Escape user input so you are not vulnerable to SQL injection attacks #7

Open
cchauche opened this issue Jul 7, 2021 · 0 comments
Open

Comments

@cchauche
Copy link

cchauche commented Jul 7, 2021

let query = `
SELECT
products.id,
products.name,
products.slogan,
products.description,
products.category,
products.default_price,
(
SELECT jsonb_agg(jsonb_build_object(
'feature', features.feature,
'value', features.value
)) AS features
FROM features
WHERE products.id = features.product_id
)
FROM products
WHERE products.id = ${productId};
`;

It looks like you are using sequalize's query() method which takes a raw SQL query as a string. From doing some research it seems that sequalize wont automatically escape these strings so you need to either use '?' placeholders instead of template literals to add user input to the query string. You can see this stack overflow article and take a look at the documentation for how to implement replacements here

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