Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ API quotas (and Anthropic credits, if narratives are on), so it has guards:

```bash
cp paradox/env.example .env # add keys and PARADOX_PASSWORD
chmod 600 .env
docker compose up -d --build
docker compose run --rm web paradox scan 45.155.205.233 --json # any headless command
```
Expand Down
6 changes: 3 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ The URL works like a password for its channel, and on the command line it shows

- [x] **PDX-36: Refuse `http://` webhooks.** Done when: the watcher refuses to start with a non-HTTPS webhook unless it points at loopback or an explicit override is set, with tests for each case.

### 4.10 Warn about a loose `.env` · S
### 4.10 Warn about a loose `.env` · S · ✅ shipped

- [ ] **PDX-37: Warn about `.env` permissions.** Done when: loading a `.env` readable by group or others prints one warning to stderr without the file's contents, a mode 600 file prints none, a test covers both, and platforms without POSIX modes are handled.
- [x] **PDX-37: Warn about `.env` permissions.** Done when: loading a `.env` readable by group or others prints one warning to stderr without the file's contents, a mode 600 file prints none, a test covers both, and platforms without POSIX modes are handled.

### 4.5 Limit which files `scan_log` can read · S · ✅ shipped

Expand Down Expand Up @@ -551,7 +551,7 @@ and fix the top issues. Repeat after 5.6. It also doubles as class material.
| When | Items | Why first |
|---|---|---|
| Now | ~~1.1, 1.2, 1.5, 3.2, 5.1~~ (done) | Small, keyless, and fix the biggest measured weakness (the scanner rule's dependence on GreyNoise); 5.1 makes that dependence visible |
| Next | 1.3, 3.1, 3.5, 3.6, 4.1, 4.10, ~~4.6, 4.7, 4.8, 4.9, 4.5, 1.7, 1.8, 3.7, 1.4, 1.6, 5.2, 5.4~~ (done) | Close the known false positives, build adversarial and hiding-place test sets, test the AI summarizer under attack, and show watch state and claim checks in the UI |
| Next | 1.3, 3.1, 3.5, 3.6, 4.1, ~~4.6, 4.7, 4.8, 4.9, 4.10, 4.5, 1.7, 1.8, 3.7, 1.4, 1.6, 5.2, 5.4~~ (done) | Close the known false positives, build adversarial and hiding-place test sets, test the AI summarizer under attack, and show watch state and claim checks in the UI |
| Then | 2.1, 2.3, 3.3, 3.4, 4.2, ~~4.3, 4.4~~ (done), 5.3, 5.5–5.7 | New unmasking signals plus self-measurement once history has accumulated, with the UI restructured to hold them |
| Later | 2.2, 2.4, 2.5 | Bigger extensions: domains, campaigns, more beacons |

Expand Down
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ the web app.

**What's in place:**

- `paradox init` creates it with mode 600.
- `paradox init` creates it with mode 600, and loading a file that others can read prints a warning with the fix.
- It's in `.gitignore` and `.dockerignore`, so it stays out of commits and images. Compose passes it at runtime.
- Status output reports whether a key is set, never its value.
- `scan_log` can't read it by default, because the working folder isn't allowed.

**Open:**

- Copying `env.example` by hand, as the Docker steps do, keeps the default permissions. Run `chmod 600 .env`.
- The file isn't checked for loose permissions when it's loaded.
- A loose `.env` only gets a warning on stderr. It still loads, so a keys file others can read keeps working.
- Windows has no such check, and a container's `env_file` is read by Docker, not this check.
- Keys are held in plain text and in the process environment.
- A key pasted into a chat or an AI session should be treated as exposed and rotated.

Expand Down
14 changes: 14 additions & 0 deletions paradox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from __future__ import annotations

import os
import sys
from pathlib import Path

PACKAGE = Path(__file__).resolve().parent
ROOT = PACKAGE.parent
POSIX_MODES = os.name == "posix" # Windows reports made-up modes


def _home() -> Path:
Expand All @@ -28,10 +30,22 @@ def _home() -> Path:
ENV_FILE = HOME / ".env"


def warn_if_exposed(path: Path) -> None:
"""A keys file others can read gives away every API key and the web password."""
if not POSIX_MODES:
return
try:
if path.stat().st_mode & 0o077:
print(f"warning: {path} can be read by other users; fix it with: chmod 600 {path}", file=sys.stderr)
except OSError:
pass


def load_dotenv(path: Path = ENV_FILE) -> None:
"""Load KEY=VALUE lines into os.environ without overriding existing vars."""
if not path.exists():
return
warn_if_exposed(path)
for line in path.read_text().splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import os
import tempfile
import unittest
Expand All @@ -7,6 +8,31 @@
from paradox import config


class ExposedKeysTests(unittest.TestCase):
def warnings(self, mode, posix=True):
with tempfile.TemporaryDirectory() as d, mock.patch.dict(os.environ, {}, clear=True), \
mock.patch("sys.stderr", io.StringIO()) as err, mock.patch.object(config, "POSIX_MODES", posix):
path = Path(d) / ".env"
path.write_text("SOME_KEY=s3cret\n")
path.chmod(mode)
config.load_dotenv(path)
self.assertEqual(os.environ["SOME_KEY"], "s3cret") # still loads
return err.getvalue()

def test_private_file_is_quiet(self):
self.assertEqual(self.warnings(0o600), "")

def test_group_or_world_access_warns_once_without_contents(self):
for mode in (0o644, 0o640, 0o604):
text = self.warnings(mode)
self.assertEqual(text.count("warning"), 1, oct(mode))
self.assertIn("chmod 600", text)
self.assertNotIn("s3cret", text)

def test_platforms_without_posix_modes_are_quiet(self):
self.assertEqual(self.warnings(0o644, posix=False), "")


class DotenvTests(unittest.TestCase):
def load(self, text):
with tempfile.TemporaryDirectory() as d, mock.patch.dict(os.environ, {}, clear=True):
Expand Down
Loading