Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

MANCHESTER-CLASS5-MIGUEL-CABRAL-SQL-WEEK3#145

Open
Miguel-Cabral wants to merge 1 commit intoCodeYourFuture:mainfrom
Miguel-Cabral:main
Open

MANCHESTER-CLASS5-MIGUEL-CABRAL-SQL-WEEK3#145
Miguel-Cabral wants to merge 1 commit intoCodeYourFuture:mainfrom
Miguel-Cabral:main

Conversation

@Miguel-Cabral
Copy link

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?

supplier_name FROM
products JOIN product_availability ON products.id = product_availability.prod_id
JOIN suppliers ON supp_id = suppliers.id `)
.then((result) => res.json(result.rows))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that this is separated out into multiple lines so it's easier to read

const customerId = req.params.id;

pool
.query("SELECT * FROM customers WHERE id=$1", [customerId])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using query parameters like this is the right way to do it!

If you did something like this:
"SELECT * FROM customers WHERE id='" + customerId +"'"

Then a user could send a request where customer id is for example ';DROP TABLES; SELECT', and try to execute SQL statements. This is called a SQL injection attack https://www.w3schools.com/sql/sql_injection.asp

When you use query parameters, the connection pool is clever enough to protect you from this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants