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).hex()

Check failure

Code scanning / SonarCloud

Password hashing functions should use an unpredictable salt

<!--SONAR_ISSUE_KEY:AY9RyOw57lEp2ttVi5PV-->Make this salt unpredictable. <p>See more on <a href="https://sonarcloud.io/project/issues?id=patched-codes_dvpwa&issues=AY9RyOw57lEp2ttVi5PV&open=AY9RyOw57lEp2ttVi5PV&pullRequest=3">SonarCloud</a></p>
15 changes: 10 additions & 5 deletions sqli/static/js/materialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ jQuery.Velocity ? console.log("Velocity is already loaded. You may be needlessly
}, addClass: function (e, t) {
e.classList ? e.classList.add(t) : e.className += (e.className.length ? " " : "") + t;
}, removeClass: function (e, t) {
e.classList ? e.classList.remove(t) : e.className = e.className.toString().replace(new RegExp("(^|\\s)" + t.split(" ").join("|") + "(\\s|$)", "gi"), " ");
e.classList ? e.classList.remove(t) : e.className = e.className.toString().replace(/(?:^|\s)${t}(?:\s|$)/gi, " ");
} }, getPropertyValue: function (e, r, n, o) {
function s(e, r) {
function n() {
Expand Down Expand Up @@ -642,7 +642,7 @@ jQuery.Velocity ? console.log("Velocity is already loaded. You may be needlessly
}), b.CSS.setPropertyValue(u, "position", e.position), b.CSS.setPropertyValue(u, "fontSize", e.fontSize), b.CSS.setPropertyValue(u, "boxSizing", "content-box"), f.each(["minWidth", "maxWidth", "width", "minHeight", "maxHeight", "height"], function (e, t) {
b.CSS.setPropertyValue(u, t, s + "%");
}), b.CSS.setPropertyValue(u, "paddingLeft", s + "em"), l.percentToPxWidth = L.lastPercentToPxWidth = (parseFloat(S.getPropertyValue(u, "width", null, !0)) || 1) / s, l.percentToPxHeight = L.lastPercentToPxHeight = (parseFloat(S.getPropertyValue(u, "height", null, !0)) || 1) / s, l.emToPx = L.lastEmToPx = (parseFloat(S.getPropertyValue(u, "paddingLeft")) || 1) / s, e.myParent.removeChild(u);
}return null === L.remToPx && (L.remToPx = parseFloat(S.getPropertyValue(r.body, "fontSize")) || 16), null === L.vwToPx && (L.vwToPx = parseFloat(t.innerWidth) / 100, L.vhToPx = parseFloat(t.innerHeight) / 100), l.remToPx = L.remToPx, l.vwToPx = L.vwToPx, l.vhToPx = L.vhToPx, b.debug >= 1 && console.log("Unit ratios: " + JSON.stringify(l), o), l;
}return null === L.remToPx && (L.remToPx = parseFloat(S.getPropertyValue(r.body, "fontSize")) || 16), null === L.vwToPx && (L.vwToPx = parseFloat(t.innerWidth) / 100, L.vhToPx = parseFloat(t.innerHeight) / 100), l.remToPx = L.remToPx, l.vwToPx = L.vwToPx, l.vhToPx = L.vhToPx, b.debug >= 1 && console.log(`Unit ratios: ${JSON.stringify(l)}`, o), l;
}if (s.begin && 0 === V) try {
s.begin.call(g, g);
} catch (x) {
Expand All @@ -658,7 +658,11 @@ jQuery.Velocity ? console.log("Velocity is already loaded. You may be needlessly
} else if ("reverse" === A) {
if (!i(o).tweensContainer) return void f.dequeue(o, s.queue);"none" === i(o).opts.display && (i(o).opts.display = "auto"), "hidden" === i(o).opts.visibility && (i(o).opts.visibility = "visible"), i(o).opts.loop = !1, i(o).opts.begin = null, i(o).opts.complete = null, v.easing || delete s.easing, v.duration || delete s.duration, s = f.extend({}, i(o).opts, s);var E = f.extend(!0, {}, i(o).tweensContainer);for (var H in E) {
if ("element" !== H) {
var N = E[H].startValue;E[H].startValue = E[H].currentValue = E[H].endValue, E[H].endValue = N, m.isEmptyObject(v) || (E[H].easing = s.easing), b.debug && console.log("reverse tweensContainer (" + H + "): " + JSON.stringify(E[H]), o);
var N = E[H].startValue;
E[H].startValue = E[H].currentValue = E[H].endValue,
E[H].endValue = N,
m.isEmptyObject(v) || (E[H].easing = s.easing),
b.debug && console.log(`reverse tweensContainer (${H}): ${JSON.stringify(E[H])}`, o);
}
}l = E;
} else if ("start" === A) {
Expand Down Expand Up @@ -696,7 +700,7 @@ jQuery.Velocity ? console.log("Velocity is already loaded. You may be needlessly
q = M + q;break;case "-":
q = M - q;break;case "*":
q = M * q;break;case "/":
q = M / q;}l[z] = { rootPropertyValue: B, startValue: M, currentValue: M, endValue: q, unitType: G, easing: $ }, b.debug && console.log("tweensContainer (" + z + "): " + JSON.stringify(l[z]), o);
q = M / q;}l[z] = { rootPropertyValue: B, startValue: M, currentValue: M, endValue: q, unitType: G, easing: $ }, b.debug && console.log(`tweensContainer (${z}): ${JSON.stringify(l[z])}`, o);
} else b.debug && console.log("Skipping [" + I + "] due to a lack of browser support.");
}l.element = o;
}l.element && (S.Values.addClass(o, "velocity-animating"), R.push(l), "" === s.queue && (i(o).tweensContainer = l, i(o).opts = s), i(o).isAnimating = !0, V === w - 1 ? (b.State.calls.push([R, g, s, null, k.resolver]), b.State.isTicking === !1 && (b.State.isTicking = !0, c())) : V++);
Expand Down Expand Up @@ -3441,7 +3445,8 @@ if (jQuery) {

// Insert as text;
} else {
toast.innerHTML = this.message;
const cleanMessage = DOMPurify.sanitize(this.message);
toast.textContent = cleanMessage;
}

// Append toasft
Expand Down