Skip to content

fix(config): fail on malformed config.json; escape values in install.sh - #141

Merged
BaaRai merged 1 commit into
mainfrom
fix/config-load-errors
Nov 3, 2026
Merged

BaaRai merged 1 commit into
mainfrom
fix/config-load-errors

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Bug

  1. config/config.go:107: Load() ran _ = json.Unmarshal(b, &c). A config.json that exists but does not parse was handled as if it were missing. Startup then failed with the misleading no database config found ... provides no database, or, when ARTEX_PG_DSN is set, skill_dir from the file was silently ignored.
  2. install.sh:80-91 (local install) wrote "password": "${DB_PASS}" and the other values into config.json with no escaping. A password containing " or \ produced invalid JSON, which bug 1 then hid.
  3. install.sh:41-42 (docker install) ran sed "s|...|POSTGRES_PASSWORD=${pw}|". A | in the password or API key broke the sed expression. A & was replaced by the matched line, and a \ was consumed.

Fix

  • config.Load() (Config, error). A missing file is still a zero Config with no error. A read error or a parse error is returned with the file path. PostgresDSN returns that error. SkillDir() (string, error) returns it too, and cmd/artex logs it and exits 1, so mgr.Close still runs.
  • install.sh: a json_str helper escapes \, ", tab and CR. host, user, password, dbname and sslmode are written through it. The port must be numeric, because it is written unquoted. A sed_repl helper escapes \, | and & for the two .env substitutions.

Verification

  • go build ./... and go vet ./...: OK (go1.26.7).
  • go test ./config ./cmd/artex ./db -count=1: ok. The new TestMalformedConfigIsAnError writes the JSON the old install.sh produced for a password containing " and expects a parse error from Load, PostgresDSN and SkillDir. TestPostgresDSNPrecedence is unchanged and passes.
  • The installer helpers were extracted from the patched install.sh and run on these passwords: plain, has"quote, back\slash, pipe|amp&both, a tab, "\|&\\", dollar$HOME and &&||. For each one, Python's json.load read the generated config.json and returned exactly the input password. The .env line produced by sed was also exactly POSTGRES_PASSWORD=<input>.
  • bash -n install.sh: OK.

Not verified:

  • I did not run the full interactive installer (it builds and starts the stack).
  • shellcheck is not installed on this machine.
  • Other control characters (below 0x20, other than tab and CR) are still not escaped. read -r cannot return a newline.
  • A password with URL-special characters (@, /, #, ?) in .env still breaks the ARTEX_PG_DSN that docker-compose.yml builds by interpolation, and $ in .env is interpolated by compose. That is a separate issue and is not changed here.

…lues

config.Load discarded the json.Unmarshal error, so a config.json that did not
parse was treated as absent: startup reported "no database config found"
and skill_dir silently fell back to the default. Load now returns read and
parse errors (a missing file is still not an error); PostgresDSN and SkillDir
pass them up, and main exits with the message.

install.sh wrote the database values into config.json unescaped, so a password
containing " or \ produced invalid JSON, which the old Load then ignored. The
values are now JSON-escaped and the port must be numeric. The .env sed
replacements escape \, | and & so those characters no longer break the
substitution or get rewritten by it.
@BaaRai
BaaRai merged commit e944716 into main Nov 3, 2026
3 checks passed
@BaaRai BaaRai mentioned this pull request Nov 4, 2026
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