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 #8

Open
wants to merge 3 commits into
base: gemini-1.5-flash-latest
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
4 changes: 4 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 All @@ -22,3 +25,4 @@ services:
- 8080:8080
command: |
wait-for postgres:5432 -- python run.py

8 changes: 4 additions & 4 deletions sqli/dao/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ 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})
async with conn.cursor() as cur:
await cur.execute(q)

await cur.execute(
"INSERT INTO students (name) VALUES (%s)",
(name,),
)

3 changes: 2 additions & 1 deletion sqli/dao/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from hashlib import md5
from typing import NamedTuple, Optional
import hashlib

from aiopg import Connection

Expand Down Expand Up @@ -38,4 +39,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 == hashlib.scrypt(password.encode('utf-8'), salt=b'saltysalt', n=2**14, r=8, p=1).hex()

Check failure

Code scanning / SonarCloud

Password hashing functions should use an unpredictable salt High

Make this salt unpredictable. See more on SonarCloud