Skip to content
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 @@ class User(NamedTuple):
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 @@ async def get_by_username(conn: Connection, username: str):
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

<!--SONAR_ISSUE_KEY:AZBM_NQm58BNI6WlRVMC-->Make this salt unpredictable. <p>See more on <a href="https://sonarcloud.io/project/issues?id=patched-codes_dvpwa&issues=AZBM_NQm58BNI6WlRVMC&open=AZBM_NQm58BNI6WlRVMC&pullRequest=10">SonarCloud</a></p>