Fix SQL injection in /api/user/:id endpoint
This commit is contained in:
parent
2d70d013ce
commit
2093e60d4f
|
@ -106,7 +106,8 @@ func server() {
|
|||
func getUser(c *gin.Context) {
|
||||
id := c.Param("userid")
|
||||
user := user{}
|
||||
err := db.QueryRow("SELECT id_alumno,nombre,apellido1,apellido2,email FROM alumnos WHERE id_alumno = "+id).Scan(&user.Id, &user.Name, &user.Surname1, &user.Surname2, &user.Email)
|
||||
dynStmt := `SELECT id_alumno,nombre,apellido1,apellido2,email FROM alumnos WHERE id_alumno = $1`
|
||||
err := db.QueryRow(dynStmt, id).Scan(&user.Id, &user.Name, &user.Surname1, &user.Surname2, &user.Email)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
c.String(http.StatusNotFound, "User not found")
|
||||
|
|
Loading…
Reference in New Issue