Skip to content

Fix SQL Injection Vulnerability #65

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

Open
wants to merge 1 commit into
base: master
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
14 changes: 7 additions & 7 deletions roles/alter_user_with_random_password.psql
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ begin
j := int4(random() * allowed_len);
pwd := pwd || substr(allowed, j+1, 1);
end loop;
sql := 'alter role ' || current_setting('postgres_dba.username')::text || ' password ''' || pwd || ''';';
sql := format('alter role %I password %L', current_setting('postgres_dba.username')::text, pwd);
raise debug 'SQL: %', sql;
execute sql;
sql := 'alter role ' || current_setting('postgres_dba.username')::text
|| (case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end)
|| ';';
sql := format('alter role %I%s',
current_setting('postgres_dba.username')::text,
(case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end));
raise debug 'SQL: %', sql;
execute sql;
sql := 'alter role ' || current_setting('postgres_dba.username')::text
|| (case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end)
|| ';';
sql := format('alter role %I%s',
current_setting('postgres_dba.username')::text,
(case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end));
raise debug 'SQL: %', sql;
execute sql;
raise debug 'User % altered, password: %', current_setting('postgres_dba.username')::text, pwd;
Expand Down
9 changes: 5 additions & 4 deletions roles/create_user_with_random_password.psql
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ begin
j := int4(random() * allowed_len);
pwd := pwd || substr(allowed, j+1, 1);
end loop;
sql := 'create role ' || current_setting('postgres_dba.username')::text
|| (case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end)
|| (case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end)
|| ' password ''' || pwd || ''';';
sql := format('create role %I%s%s password %L',
current_setting('postgres_dba.username')::text,
(case when lower(current_setting('postgres_dba.is_superuser')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' superuser' else '' end),
(case when lower(current_setting('postgres_dba.login')::text) not in ('0', '', 'no', 'false', 'n', 'f') then ' login' else '' end),
pwd);
raise debug 'SQL: %', sql;
execute sql;
raise info 'User % created, password: %', current_setting('postgres_dba.username')::text, pwd;
Expand Down