Skip to content

Create FileHistory file with owner-only permissions - #2156

Open
neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:file-history-permissions
Open

neeraj1235476 wants to merge 1 commit into
prompt-toolkit:mainfrom
neeraj1235476:file-history-permissions

Conversation

@neeraj1235476

Copy link
Copy Markdown
Contributor

FileHistory.store_string creates the history file with open(filename, "ab"), so under the usual 022 umask it ends up 0644 and any local user can read it. That file holds everything typed at the prompt, and for tools built on FileHistory (pgcli, mycli, ptpython) that includes SQL with passwords, tokens and connection strings. GNU readline, and therefore psql and bash, create their history files 0600.

Create the file with os.open(..., 0o600) so a new history file is owner-only. Files that already exist keep their mode, and O_BINARY keeps the Windows behaviour the same as before. Doing this inside FileHistory means each application doesn't have to pre-create the file or adjust its umask. test_file_history_permissions in tests/test_history.py fails before this change and passes after it.

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