Repository navigation
fix(config): fail on malformed config.json; escape values in install.sh - #141
Merged
Merged
Conversation
…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.
Merged
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.
Bug
config/config.go:107:Load()ran_ = json.Unmarshal(b, &c). Aconfig.jsonthat exists but does not parse was handled as if it were missing. Startup then failed with the misleadingno database config found ... provides no database, or, whenARTEX_PG_DSNis set,skill_dirfrom the file was silently ignored.install.sh:80-91(local install) wrote"password": "${DB_PASS}"and the other values intoconfig.jsonwith no escaping. A password containing"or\produced invalid JSON, which bug 1 then hid.install.sh:41-42(docker install) ransed "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.PostgresDSNreturns that error.SkillDir() (string, error)returns it too, andcmd/artexlogs it and exits 1, somgr.Closestill runs.install.sh: ajson_strhelper escapes\,", tab and CR.host,user,password,dbnameandsslmodeare written through it. The port must be numeric, because it is written unquoted. Ased_replhelper escapes\,|and&for the two.envsubstitutions.Verification
go build ./...andgo vet ./...: OK (go1.26.7).go test ./config ./cmd/artex ./db -count=1: ok. The newTestMalformedConfigIsAnErrorwrites the JSON the old install.sh produced for a password containing"and expects a parse error fromLoad,PostgresDSNandSkillDir.TestPostgresDSNPrecedenceis unchanged and passes.install.shand run on these passwords:plain,has"quote,back\slash,pipe|amp&both, a tab,"\|&\\",dollar$HOMEand&&||. For each one, Python'sjson.loadread the generatedconfig.jsonand returned exactly the input password. The.envline produced bysedwas also exactlyPOSTGRES_PASSWORD=<input>.bash -n install.sh: OK.Not verified:
read -rcannot return a newline.@,/,#,?) in.envstill breaks theARTEX_PG_DSNthatdocker-compose.ymlbuilds by interpolation, and$in.envis interpolated by compose. That is a separate issue and is not changed here.