fix(dark-tariff): patch SQLi, weak calculation_id, and ZKP challenge bias
This commit is contained in:
1 parent
1857506f60
commit
58bdfcb829
5 files changed
+312
-16
No files matched your search
@@ -27,10 +27,9 @@ declare
|
||||
begin
|
||||
loop
|
||||
v := get_byte(gen_random_bytes(1), 0);
|
||||
exit when v < 200;
|
||||
exit when v < 252;
|
||||
end loop;
|
||||
v := v % 100;
|
||||
return case when v < 70 then 0 when v < 95 then 1 else 2 end;
|
||||
return v % 3;
|
||||
end;
|
||||
$$;
|
||||
|
||||
@@ -129,11 +128,25 @@ create or replace function chat.check_start(p_reading bigint) returns jsonb
|
||||
language plpgsql as $$
|
||||
declare
|
||||
v_id uuid;
|
||||
v_failed integer;
|
||||
v_active integer;
|
||||
begin
|
||||
perform 1 from billing.reading where id = p_reading and created_at > now() - interval '10 minutes' for key share;
|
||||
select failed_checks into v_failed
|
||||
from billing.reading
|
||||
where id = p_reading and created_at > now() - interval '10 minutes'
|
||||
for update;
|
||||
if not found then
|
||||
raise exception 'Reading not found.' using errcode = 'P0404';
|
||||
end if;
|
||||
if v_failed >= 4 then
|
||||
raise exception 'Too many failed verification attempts.' using errcode = 'P0403';
|
||||
end if;
|
||||
select count(*) into v_active
|
||||
from chat.check_session
|
||||
where reading_id = p_reading and not complete;
|
||||
if v_active >= 2 then
|
||||
raise exception 'Another verification is already in progress.' using errcode = 'P0409';
|
||||
end if;
|
||||
insert into chat.check_session (reading_id) values (p_reading) returning id into v_id;
|
||||
return jsonb_build_object('id', v_id, 'round', 1, 'stage', 'commit',
|
||||
'message', 'Step 1 of 10. Submit three values.');
|
||||
@@ -185,6 +198,7 @@ begin
|
||||
end if;
|
||||
if not coalesce(chat.valid_response(v_reading, v_session.data, v_session.challenge, p_data), false) then
|
||||
delete from chat.check_session where id = p_id;
|
||||
update billing.reading set failed_checks = failed_checks + 1 where id = v_session.reading_id;
|
||||
return jsonb_build_object('stage', 'failed', 'message', 'Verification failed. Try again.');
|
||||
end if;
|
||||
if p_round = 10 then
|
||||
|
||||
Reference in new issue
Block a user