fix(config): restrict censys.cfg to owner-only permissions - #720
Merged
Conversation
6 tasks
Aidan Holland (thehappydinoa)
requested review from
Aidan Holland (thehappydinoa)
and
a lite review from Copilot
August 27, 2026 20:00
Copilot started reviewing on behalf of
Aidan Holland (thehappydinoa)
August 27, 2026 20:00
View session
There was a problem hiding this comment.
Pull request overview
This PR hardens config credential storage by ensuring the Censys config directory and file are created (and, when possible, tightened) with owner-only permissions to avoid leaking plaintext API credentials on shared hosts.
Changes:
- Add a restricted
open()opener (0600) and best-effort chmod helper to tighten existing config paths. - Create the default config directory with mode 0700 and attempt to chmod pre-existing directories/files to 0700/0600.
- Update CLI config tests and add real-filesystem POSIX tests verifying permissions on fresh writes and rewrites.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
censys/common/config.py |
Enforces owner-only permissions for the config dir/file via mode=0o700, opener with 0o600, and best-effort chmod on rewrites. |
tests/cli/test_config.py |
Updates mocks for the new open(..., opener=...) / makedirs(..., mode=...) behavior and adds POSIX filesystem permission tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Create ~/.config/censys with mode 0700 and write censys.cfg with mode 0600 instead of inheriting the process umask, and tighten permissions on pre-existing files/directories on rewrite. Under the default umask of 022 the config file was previously world-readable (0644), exposing api_secret and asm_api_key to other local users (CWE-276).
Ben Schwartz (btschwartz12)
force-pushed
the
fix-config-perms
branch
3 times, most recently
from
August 27, 2026 20:45
4b3847b to
6f09e75
Compare
Ben Schwartz (btschwartz12)
force-pushed
the
fix-config-perms
branch
from
August 27, 2026 20:48
6f09e75 to
d147cc7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
write_config()created~/.config/censysand wrotecensys.cfgwithout an explicit mode, so permissions were governed solely by the process umask. Under the common default umask of022, the config file — which holdsapi_id,api_secret, andasm_api_keyin plaintext — ended up world-readable (0644) and the directory world-traversable (0755). On shared hosts, any local unprivileged user could read the victim's live API credentials (CWE-276, Incorrect Default Permissions).This change hardens
write_config()so it no longer inherits the ambient umask:0700(and chmod'd to0700if it already exists).0600via anopenerthat passes0o600toos.open(), and any pre-existing file is chmod'd to0600before credentials are written to it.Changes
censys/common/config.py:write_config()now creates the config directory0700, creates the config file0600, and tightens permissions on pre-existing files/directories on rewrite.tests/cli/test_config.py: adjusted existing assertions for the newopen()/makedirs()calls and addedtest_write_config_restricts_permissions, a real-filesystem test verifying0700/0600for both fresh writes and rewrites over loose-permission files.Checklist