aft icon indicating copy to clipboard operation
aft copied to clipboard

`aft --help` starts the server on the default storage and prints no usage

Open iceteaSA opened this issue 2 weeks ago • 2 comments

What occurs

aft --help does not print usage. The binary has no branch for --help or -h, so it continues to the usual server start. The server start opens the default storage root and writes a log file there.

On v0.66.0, crates/aft/src/main.rs reads these arguments before the server start: --formats, --version / -V, migrate-storage, index and grammar-smoke. There is no --help or -h in that list.

We saw this on v0.64.0. A run of aft --help started the server on the default storage of a live installation. It left a new log file there. Nothing else changed, because the run used the same version as the installation.

Why this is a risk

A person who examines a newly downloaded binary frequently runs --help first. If that binary is newer than the installed one, the run opens the installed storage with the newer version. A newer version can migrate the storage, and the older installed version then cannot read it. The documentation says that --formats has no side effects because of this risk. --help gives no such protection.

Correct result

aft --help and aft -h print usage and exit 0, with no storage access, no logging and no PATH probe, the same as --version and --formats.

Possible repair

Read --help and -h at the same point as --version, before the storage and logging start. Also, an unknown first argument that starts with - could stop with a usage error, not with the server start.

iceteaSA avatar Nov 17 '26 17:11 iceteaSA

Thanks, confirmed. aft --help fell through to the normal server start, so it opened the default storage and wrote a log there. As you point out, a newer binary run that way could touch an installed AFT's storage.

The fix makes aft --help and aft -h print usage and exit 0 before AFT opens storage, writes a log or probes PATH, the same as --version and --formats. An unknown option as the first argument now stops with aft: unknown option '<arg>' and the usage text, exit code 2, instead of starting the server. A test runs each case with an empty home and storage folder and checks that both stay empty.

It will ship in the next release. I'll close this issue when that release is published.

aft-alfonso[bot] avatar Nov 17 '26 19:11 aft-alfonso[bot]

Thanks, @iceteaSA. Fixed in v0.67.1: aft --help now prints usage and exits without starting the server or touching storage, and an unknown command exits with a usage error (exit code 2). Please reopen if you still see it.

aft-alfonso[bot] avatar Nov 24 '26 11:11 aft-alfonso[bot]