Skip to content

fix: owner-only cache permissions, portable auth tests, bounded CI - #102

Open
axsddlr wants to merge 7 commits into
jackwener:mainfrom
axsddlr:infra-fixes
Open

axsddlr wants to merge 7 commits into
jackwener:mainfrom
axsddlr:infra-fixes

Conversation

@axsddlr

@axsddlr axsddlr commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Seven small, independent fixes on top of main. They do not depend on any open PR, and each stands alone.

While triaging all 29 open PRs I found that the repo cannot currently merge any of the substantive community fixes — every clustered PR fails or never runs (see "CI reality" below). These commits are the gaps none of the open PRs cover, and they make the tree green on Windows as well as Linux.

1. fix(security): write cache files owner-only

_save_ct_cache() writes ~/.twitter-cli/transaction_cache.json with a plain open(), so the file inherits the process umask — typically 0644, i.e. readable by every other local user. That JSON embeds the full x.com/home HTML, which contains the session's live auth_token/ct0. ~/.twitter-cli/last_results.json (tweet text the user read) had the same problem.

Both now go through a shared helper that passes 0o600 to os.open() on create, so the file is never briefly world-readable (plain open() + later chmod leaves a window), and fchmods an existing file to narrow permissions left by an older build. Cache directories are tightened to 0700.

Best-effort by design: permission changes must never fail the command that triggered a cache write, and on Windows chmod only toggles the read-only bit.

Severity: defense-in-depth, not a remote vuln — POSIX credentials also sit world-readable in browser cookie DBs. Still cheap, and no open PR addresses it.

Negative control (real Linux, old code vs new tests): 4 failed, 1 passed of 5 on the previous implementation, 5 passed now.

2. test(auth): make browser-path tests platform-independent

This is what makes the suite green on Windows. Four browser-cookie-path tests only passed on POSIX:

  • they redirected HOME, but Windows ntpath.expanduser reads USERPROFILE, so the fake profile tree was never found;
  • they branch on sys.platform to build the fixture, yet tests that pin sys.platform cannot use it to decide where to build the tree — and platform.system() derives from the patched sys.platform, so it is unreliable too (os.name is fixed at interpreter start and is immune);
  • two assertions hard-coded POSIX separators (.config/x/Default/Cookies).

No production code changes.

before: 3 failed, 242 passed   (upstream main, on Windows)
after:  245 passed, 2 skipped  (same suite, on Windows)

(On Linux both pass in full: 247 passed.)

3. ci: bound job time and document the fork-approval gate

Two things made PR status unreadable rather than merely wrong:

Adds a 20-minute job cap with per-step timeouts, uv caching, fail-fast: false (so one Python version failing does not hide the other two), permissions: contents: read, persist-credentials: false, pull-request concurrency cancellation, and a comment documenting the approval setting a maintainer can switch off.

4. ci: move to Node 24 action majors

checkout@v4, setup-python@v5 and setup-uv@v6 target Node 20, which now warns on every run. Moved to checkout@v7 / setup-python@v7 / setup-uv@v10.3.3 (setup-uv publishes no floating v10 tag, so the release is pinned).

5. ci: pin the runner image

ubuntu-latest migrates to Ubuntu 26 in Oct 2026 and is otherwise a moving target; pinned to ubuntu-24.04.

6. ci: align Python support validation and badges

Adds Python 3.13 to the test matrix. requires-python is >=3.10, so 3.13 is supported but previously untested; verified green in CI (test (3.13) passes) and locally. Also switches to the dynamic PyPI-python-versions badge. (Restored from a fork-only commit that predates the public-clis rename; its 3.8/3.9 entries were dropped because upstream raised the floor to 3.10.)

7. fix(cache): resolve fchmod without a version-specific type ignore

mypy 1.14 (the pinned version) reports a direct os.fchmod call as an unused ignore, while newer mypy needs the ignore because fchmod is missing from some typeshed variants. Resolved through getattr, so it type-checks on both.

CI reality (why the cluster is stuck)

Verification

Reproduced what CI runs with the project's pinned tooling (ruff 0.15.4, mypy 1.14.1), on this branch:

Host ruff mypy pytest
Linux 3.12 pass pass 247 passed, 0 failed
Linux 3.13 pass pass 247 passed, 0 failed
Windows pass pass 245 passed, 2 skipped

The 2 skips are the permission-bit tests, which assert 0600/0700 and cannot pass on Windows (stat.S_IMODE returns 0o666); they run on Linux.

CI on a fork: test (3.10 / 3.11 / 3.12 / 3.13) all pass, zero annotations.

Several browser cookie-path tests only passed on POSIX hosts:

* They redirected `HOME` but Windows `ntpath.expanduser` reads
  `USERPROFILE`, so the fake profile tree was never found.
* They branch on `sys.platform` to build the fixture, but tests that pin
  `sys.platform` to exercise POSIX branches cannot use it to decide where
  to build the tree; and `platform.system()` derives from the patched
  `sys.platform` so it is unreliable too.
* Two assertions hard-coded POSIX separators ('.config/x/Default/Cookies').

Add a `_patch_home` helper (HOME + USERPROFILE, keyed off `os.name`)
and pin the POSIX layout explicitly where a test is asserting POSIX
behaviour. Compare paths with os.path.join instead of literal separators.

No production code changes; this makes the existing suite green on Windows
as well as Linux/macOS.
The ClientTransaction cache stores the full x.com/home HTML, which embeds the
session's live auth_token/ct0. It was written with a plain open(), so it
inherited the process umask - typically 0644, i.e. readable by every other
local user on the host. The index cache (~/.twitter-cli/last_results.json)
holds tweet text the user read and had the same problem.

Create both through a shared helper that passes 0o600 to os.open() on create
(so the file is never briefly world-readable) and fchmods an existing file to
narrow permissions left by an older build. Cache directories are tightened to
0700. The helper is best-effort by design: permission changes must never fail
the command that triggered a cache write, and on Windows chmod only toggles
the read-only bit.

Tests assert 0600/0700 on POSIX and are skipped elsewhere, and a negative
control confirms they fail against the previous implementation.
Two things made PR status unreadable rather than wrong:

* No job timeout, so a stalled install/test run inherited GitHub's 30-day
  ceiling (runs sat at 'failure 720h' and read as code failures).
* First-time contributors hit 'action_required', where the workflow never
  starts and no checks are reported at all.

Set a 20-minute job cap with per-step timeouts, enable uv caching, drop
persisted credentials from checkout, add least-privilege permissions and
pull-request concurrency cancellation, and document the approval setting
maintainers can change.

Also fixed the matrix to fail-fast: false so one Python version failing
does not hide the others on this 3-version matrix.
mypy 1.14 (the version this project pins) reports the direct os.fchmod call as
an unused ignore, while newer mypy needs the ignore because fchmod is missing
from some typeshed variants. Resolve it through getattr instead, so the code
type-checks cleanly on both.
axsddlr and others added 3 commits October 31, 2026 04:15
Actions targeting Node 20 (checkout@v4, setup-python@v5, setup-uv@v6) now
emit a deprecation warning on every run. Move to the current majors, which
run on node24: checkout@v7, setup-python@v7, setup-uv@v10.3.3 (setup-uv
publishes no floating v10 tag, so the release is pinned).
ubuntu-latest migrates to Ubuntu 26 in Oct 2026 and is otherwise a moving
target, so a green run today does not prove the next one. Pin ubuntu-24.04.

This branch has not been deployed

No deployments
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.

2 participants