-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
675aca2
commit 7a20965
Showing
33 changed files
with
976 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export BEARER_VERSION=latest | ||
export BEARER_WORKSPACE=$PWD/../bearer | ||
export GO_EXEC=go | ||
export BEARER_DISABLE_VERSION_CHECK=true | ||
export BEARER_DISABLE_DEFAULT_RULES=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package sqli | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/foo/utils/database" | ||
) | ||
|
||
var DB *sql.DB | ||
var err error | ||
|
||
type Profile struct { | ||
Uid int | ||
Name string | ||
City string | ||
PhoneNumber string | ||
} | ||
|
||
func NewProfile() *Profile { | ||
return &Profile{} | ||
} | ||
|
||
func (p *Profile) UnsafeQueryGetData(uid string) error { | ||
|
||
/* this funciton use to get data Profile from database with vulnerable query */ | ||
DB, err = database.Connect() | ||
|
||
getProfileSql := fmt.Sprintf(`SELECT p.user_id, p.full_name, p.city, p.phone_number | ||
FROM Profile as p,Users as u | ||
where p.user_id = u.id | ||
and u.id=%s`, uid) //here is the vulnerable query | ||
|
||
// bearer:expected go_gosec_sql_concat_sqli | ||
rows, err := DB.Query(getProfileSql) | ||
if err != nil { | ||
return err | ||
} | ||
defer rows.Close() | ||
|
||
for rows.Next() { | ||
err = rows.Scan(&p.Uid, &p.Name, &p.City, &p.PhoneNumber) | ||
if err != nil { | ||
log.Printf("Row scan error: %s", err.Error()) | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (p *Profile) SafeQueryGetData(uid string) error { | ||
DB, err = database.Connect() | ||
|
||
const ( | ||
getProfileSql = `SELECT p.user_id, p.full_name, p.city, p.phone_number | ||
FROM Profile as p,Users as u | ||
where p.user_id = u.id | ||
and u.id=?` | ||
) | ||
|
||
stmt, err := DB.Prepare(getProfileSql) //prepare statement | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer stmt.Close() | ||
err = stmt.QueryRow(uid).Scan(&p.Uid, &p.Name, &p.City, &p.PhoneNumber) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.