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

PatchWork AutoFix #10

Open
wants to merge 3 commits into
base: gpt-3.5-turbo-0125
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ services:

redis:
image: redis:alpine
security_opt:
- "no-new-privileges:true"
read_only: true

sqli:
build:
Expand Down
7 changes: 2 additions & 5 deletions sqli/dao/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ async def get_many(conn: Connection, limit: Optional[int] = None,

@staticmethod
async def create(conn: Connection, name: str):
q = ("INSERT INTO students (name) "
"VALUES ('%(name)s')" % {'name': name})
q = "INSERT INTO students (name) VALUES (%s)"
async with conn.cursor() as cur:
await cur.execute(q)


await cur.execute(q, (name,))
6 changes: 3 additions & 3 deletions sqli/dao/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hashlib import md5
from hashlib import scrypt
from typing import NamedTuple, Optional

from aiopg import Connection
Expand All @@ -10,7 +10,7 @@
middle_name: Optional[str]
last_name: str
username: str
pwd_hash: str
pwd_hash: bytes
is_admin: bool

@classmethod
Expand Down Expand Up @@ -38,4 +38,4 @@
return User.from_raw(await cur.fetchone())

def check_password(self, password: str):
return self.pwd_hash == md5(password.encode('utf-8')).hexdigest()
return self.pwd_hash == scrypt(password.encode('utf-8'), salt=b'salt', n=16384, r=8, p=1)

Check failure

Code scanning / SonarCloud

Password hashing functions should use an unpredictable salt High

Make this salt unpredictable. See more on SonarCloud