-
Notifications
You must be signed in to change notification settings - Fork 462
Fix A3 SSType #643
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
base: master
Are you sure you want to change the base?
Fix A3 SSType #643
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,8 +46,8 @@ func AuthenticateUser(user string, pass string) (bool, error) { | |
| } | ||
| defer dbConn.Close() | ||
|
|
||
| query := fmt.Sprint("select * from Users where username = '" + user + "'") | ||
| rows, err := dbConn.Query(query) | ||
| query := ("SELECT * FROM Users WHERE username = ?") | ||
| rows, err := dbConn.Query(query, user) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
@@ -88,12 +88,12 @@ func NewUser(user string, pass string, passcheck string) (bool, error) { | |
| } | ||
| defer dbConn.Close() | ||
|
|
||
| query := fmt.Sprint("insert into Users (username, password) values ('" + user + "', '" + passHash + "')") | ||
| rows, err := dbConn.Query(query) | ||
| query := ("INSERT INTO Users (username, password) VALUES (?, ?)") | ||
| rows, err := dbConn.Exec(query, user, passHash) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| defer rows.Close() | ||
|
|
||
|
|
||
| fmt.Println("User created: ", user) | ||
| return true, nil //user created | ||
|
|
@@ -108,8 +108,8 @@ func CheckIfUserExists(username string) (bool, error) { | |
| } | ||
| defer dbConn.Close() | ||
|
|
||
| query := fmt.Sprint("select username from Users where username = '" + username + "'") | ||
| rows, err := dbConn.Query(query) | ||
| query := ("SELECT username FROM Users WHERE username = ?") | ||
| rows, err := dbConn.Query(query, username) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
@@ -126,16 +126,16 @@ func InitDatabase() error { | |
|
|
||
| dbConn, err := OpenDBConnection() | ||
| if err != nil { | ||
| errOpenDBConnection := fmt.Sprintf("OpenDBConnection error: %s", err) | ||
| errOpenDBConnection := ("OpenDBConnection error: %s" + err) | ||
| return errors.New(errOpenDBConnection) | ||
| } | ||
|
|
||
| defer dbConn.Close() | ||
|
|
||
| queryCreate := fmt.Sprint("CREATE TABLE Users (ID int NOT NULL AUTO_INCREMENT, Username varchar(20), Password varchar(80), PRIMARY KEY (ID))") | ||
| queryCreate := ("CREATE TABLE Users (ID int NOT NULL AUTO_INCREMENT, Username varchar(20), Password varchar(80), PRIMARY KEY (ID))") | ||
| _, err = dbConn.Exec(queryCreate) | ||
| if err != nil { | ||
| errInitDB := fmt.Sprintf("InitDatabase error: %s", err) | ||
| errInitDB := ("InitDatabase error: %s" + err) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same question as line 129.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same response for line 129 |
||
| return errors.New(errInitDB) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| POST /login HTTP/1.1 | ||
| Host: 127.0.0.1:10001 | ||
| User-Agent: curl/7.54.0 | ||
| Accept: */* | ||
| Content-Type: application/json | ||
| Content-Lenght: 31 | ||
|
|
||
| {"user":"-1' UNION SELECT 1,2,sleep(5) -- ", "pass":"password"} | ||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commit is about another application. Could you split this PR into three others?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did the labs in sequence and I think I didn't start the branch at the right time for SSType, can you help me fix this? Should I delete the PRs and redo? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ mysqlclient==1.3.13 | |
| six==1.11.0 | ||
| visitor==0.1.3 | ||
| Werkzeug==0.14.1 | ||
| bleach==5.0.1 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you make this modification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has nothing to do with the vulnerability, I just saw that it is a string formatting practice in Go