Skip to content

Conversation

NikolayS
Copy link
Owner

@NikolayS NikolayS commented Sep 29, 2025

Summary

Enhances role management functionality by adding interactive user creation and password management tools to the main menu, while improving security and overall menu quality.

Changes

New features

  • r1: Create user with random password (interactive)
  • r2: Alter user with random password (interactive)

These scripts are now accessible from the main :dba menu, making secure role management more convenient for DBAs.

Security improvements

  • Replace string concatenation with format() function in role management scripts
  • Use %I for identifier quoting (prevents issues with special characters in usernames)
  • Use %L for literal escaping (prevents issues with special characters in passwords)
  • Files modified:
    • roles/alter_user_with_random_password.psql
    • roles/create_user_with_random_password.psql

Menu improvements

  • Fix typo: lightweight (was leightweight)
  • Improve clarity: spell out abbreviations (database, Foreign keys, temporary, username)
  • Update terminology: primary/replica (modern Postgres terminology)
  • Apply sentence-style capitalization consistently
  • Use binary units: GiB instead of GB in memory prompts

Infrastructure

  • Restore version check variables (postgres_dba_pgvers_17plus, postgres_dba_pgvers_13plus)
  • Update generate.sh to include version checks in warmup.psql

Context

The role management scripts were already present in the roles/ directory but not accessible from the interactive menu. This PR makes them discoverable and usable, while also improving their implementation to handle edge cases with special characters in usernames and passwords.

Since these scripts are intended for DBA use in interactive psql sessions where DBAs typically have full database access, the security improvements primarily address edge cases with special characters rather than preventing malicious attacks.

@NikolayS NikolayS changed the title 🔒 SECURITY: Comprehensive SQL injection vulnerability fixes fix(roles): SQL injection in role management Sep 30, 2025
Replace string concatenation with format() function in role management
scripts to prevent SQL injection with special characters in usernames
or passwords.

Use %I for identifier quoting and %L for literal escaping. While these
scripts are intended for DBA use in interactive sessions, using format()
is better practice and handles edge cases with special characters.

Files modified:
- roles/alter_user_with_random_password.psql
- roles/create_user_with_random_password.psql

Co-Authored-By: Claude <[email protected]>
@NikolayS NikolayS force-pushed the security/fix-sql-injection-vulnerabilities branch from 62376b0 to a269478 Compare September 30, 2025 00:03
- Fix typo: lightweight (was leightweight) in l1
- Use GiB instead of GB in memory prompt per binary units rule
- Spell out abbreviations: DB → database, FKs → Foreign keys, tmp → temporary
- Update terminology: master/replica → primary/replica (modern Postgres terminology)
- Fix inconsistencies: user name → username, do & undo → do and undo
- Remove redundant prefix in v2 description
start.psql Outdated
\echo ' t1 – PostgreSQL parameters tuning'
\echo ' v1 – Vacuum: current activity'
\echo ' v2 – Vacuum: VACUUM progress and autovacuum queue'
\echo ' v2 – Vacuum: vacuum progress and autovacuum queue'
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think VACUUM here should be uppercase

@@ -1,4 +1,4 @@
--Vacuum: VACUUM progress and autovacuum queue
--Vacuum: vacuum progress and autovacuum queue
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VACUUM was fine here

- Restore postgres_dba_pgvers_17plus and _13plus version checks
- Revert VACUUM to uppercase (SQL command)
- Revert 'Postgres' terminology (preferred over PostgreSQL)
- Revert DO & UNDO to uppercase (migration operations)
@NikolayS NikolayS changed the title fix(roles): SQL injection in role management feat(roles): add role management to menu and improve security Sep 30, 2025
@NikolayS NikolayS merged commit 7530d44 into master Sep 30, 2025
6 checks passed
@NikolayS NikolayS deleted the security/fix-sql-injection-vulnerabilities branch September 30, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant