Limit field lengths in logins
It is open to the public so people could abuse the storage Also switch to text type everywhere
This commit is contained in:
@@ -34,13 +34,16 @@ $$ LANGUAGE plpgsql;
|
|||||||
|
|
||||||
create table if not exists
|
create table if not exists
|
||||||
basic_auth.logins (
|
basic_auth.logins (
|
||||||
username character varying not null,
|
username text not null,
|
||||||
pass character(60) not null,
|
pass text not null,
|
||||||
role name not null,
|
role name not null,
|
||||||
email character varying not null unique,
|
email text not null unique,
|
||||||
active boolean not null default false,
|
active boolean not null default false,
|
||||||
more JSON,
|
more JSON,
|
||||||
constraint l_pkey primary key (username)
|
constraint l_pkey primary key (username),
|
||||||
|
constraint login_field_length_limits check (
|
||||||
|
length(username::text) < 512 AND length(pass) < 512 AND
|
||||||
|
length(email::text) < 512 AND length(more::text) < 1024)
|
||||||
);
|
);
|
||||||
|
|
||||||
create or replace function
|
create or replace function
|
||||||
@@ -86,7 +89,7 @@ basic_auth.send_validation() returns trigger
|
|||||||
language plpgsql
|
language plpgsql
|
||||||
as $$
|
as $$
|
||||||
declare
|
declare
|
||||||
tok character varying;
|
tok text;
|
||||||
begin
|
begin
|
||||||
select uuid_generate_v4() into tok;
|
select uuid_generate_v4() into tok;
|
||||||
insert into basic_auth.tokens (token, token_type, username)
|
insert into basic_auth.tokens (token, token_type, username)
|
||||||
@@ -114,9 +117,9 @@ create trigger send_validation_t
|
|||||||
|
|
||||||
create table if not exists
|
create table if not exists
|
||||||
basic_auth.tokens (
|
basic_auth.tokens (
|
||||||
token character varying unique,
|
token text unique,
|
||||||
token_type varchar(64) not null,
|
token_type text not null,
|
||||||
username character varying not null,
|
username text not null,
|
||||||
created_at timestamptz not null default current_date,
|
created_at timestamptz not null default current_date,
|
||||||
constraint t_pk primary key (token),
|
constraint t_pk primary key (token),
|
||||||
constraint t_login_fk foreign key (username) references basic_auth.logins
|
constraint t_login_fk foreign key (username) references basic_auth.logins
|
||||||
@@ -147,7 +150,7 @@ request_password_reset(username text) returns void
|
|||||||
language plpgsql
|
language plpgsql
|
||||||
as $$
|
as $$
|
||||||
declare
|
declare
|
||||||
tok character varying;
|
tok text;
|
||||||
begin
|
begin
|
||||||
delete from basic_auth.tokens
|
delete from basic_auth.tokens
|
||||||
where token_type = 'reset'
|
where token_type = 'reset'
|
||||||
@@ -175,7 +178,7 @@ reset_password(username text, token text, pass text)
|
|||||||
language plpgsql
|
language plpgsql
|
||||||
as $$
|
as $$
|
||||||
declare
|
declare
|
||||||
tok character varying;
|
tok text;
|
||||||
begin
|
begin
|
||||||
if exists(select 1 from basic_auth.tokens
|
if exists(select 1 from basic_auth.tokens
|
||||||
where tokens.username = reset_password.username
|
where tokens.username = reset_password.username
|
||||||
@@ -220,7 +223,7 @@ create_auth_token(username text, pass text) returns basic_auth.jwt_claims
|
|||||||
language plpgsql
|
language plpgsql
|
||||||
as $$
|
as $$
|
||||||
declare
|
declare
|
||||||
_role character varying;
|
_role text;
|
||||||
result basic_auth.jwt_claims;
|
result basic_auth.jwt_claims;
|
||||||
begin
|
begin
|
||||||
select basic_auth.login_role(username, pass) into _role;
|
select basic_auth.login_role(username, pass) into _role;
|
||||||
|
|||||||
Reference in New Issue
Block a user