fix(config): enforce full validation on CLI flags#511
Merged
aaronbrethorst merged 1 commit intoOneBusAway:mainfrom Mar 1, 2026
Merged
fix(config): enforce full validation on CLI flags#511aaronbrethorst merged 1 commit intoOneBusAway:mainfrom
aaronbrethorst merged 1 commit intoOneBusAway:mainfrom
Conversation
Extracted the validation logic by exporting JSONConfig.Validate() and applying it to CLI-provided configuration. This ensures that parameters like port ranges, rate limits, API keys, and file paths are strictly validated regardless of whether the app is configured via JSON or CLI flags, closing the validation bypass gap
aaronbrethorst
approved these changes
Mar 1, 2026
Member
aaronbrethorst
left a comment
There was a problem hiding this comment.
Hey Adel, clean solution here — reusing Validate() instead of duplicating rules is exactly the right call. The restructuring of the CLI path to pack flags into a JSONConfig and run the shared validation + conversion pipeline makes the two config paths symmetrical, which is much easier to reason about.
Fit and Finish
1. Remove the // DRY! and // This allows us to... comments (follow-up PR)
The two inline comments at the top of the CLI block are more noise than signal:
// Pack the CLI flags into a temporary JSONConfig struct
// This allows us to run the exact same robust validation logic as the JSON path!and
// Convert to internal app configs (DRY!)The code is self-explanatory — a JSONConfig being validated and converted speaks for itself. Could you remove both in a quick follow-up?
Verification
- Tests: all pass
- Lint: 0 issues
Validate()export is clean —JSONConfigis already exported, so making its validation method public is consistent- Flag defaults match
setDefaults()values, so skippingsetDefaults()in the CLI path is correct ToGtfsConfigData()correctly defaultsEnabledtotruewhenfeed.Enabledis nil, so the omittedEnabled: trueonGtfsRtFeedin the CLI struct is fineParseAPIKeys("")returns[]string{}whichValidate()correctly rejects as "api-keys cannot be empty"- CLA: signed
Strengths
- DRY in practice, not just in theory: Instead of copying validation rules or adding a second validation pass, this funnels CLI flags through the existing validated pipeline. One set of rules, two entry points.
- Net deletion: 41 lines removed, 56 added, but the added lines include the
JSONConfigstruct literal which replaces scattered manual assignments. The result is structurally simpler. - Correct defaults: The flag defaults (port 4000, env "development", rate-limit 100, etc.) align with
setDefaults(), so the CLI path doesn't need to callsetDefaults()— the values are already populated fromflag.Parse().
Merging now. Thanks Adel! Please take care of the followups sometime soon!
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.
Description
This PR addresses the configuration validation bypass issue where validation rules were only applied when loading configurations from a JSON file, leaving CLI flags unchecked.
The Problem:
Previously, an operator could start the server via CLI flags with misconfigured values (e.g., port=0, empty API keys, invalid rate limits) and receive no warnings or errors, potentially leading to insecure or unstable states.
The Solution:
Instead of duplicating the validation logic, this PR enforces the existing robust validation rules on CLI inputs by:
Exporting the validate() method to Validate() in internal/appconf/json_config.go.
Packing the parsed CLI flags into a temporary JSONConfig struct in cmd/api/main.go.
Running the shared Validate() method before converting the struct to the internal app configurations.
Impact:
CLI inputs are now strictly protected by the same rules as JSON configurations, including:
Port range enforcement (1-65535)
Valid environment name checks
Rate limit minimums
Non-empty and duplicate API key detection
Path traversal prevention for data paths
@aaronbrethorst
fixes : #498