Skip to content

Validate domain hosts and store codes before they reach nginx - #162

Merged
peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:fix/validate-store-map-values
Nov 12, 2026
Merged

peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:fix/validate-store-map-values

Conversation

@Aquive

@Aquive Aquive commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Found by: the security-guidance Claude Code plugin (automated security review), which flagged this after syncing upstream main.

Problem

host and store_code from .magebox.yaml are written unquoted into 000-magebox-store-map.conf, which every project shares:

map $host $MAGE_RUN_CODE {
    default "";
    {{.Host}}    {{.Code}};
}

Config.Validate() only checked store_type. A value with a space, ; or } closes the map block, so a store_code like x; } server { ... } injects arbitrary directives into the http context. More practically, an honest typo (a space or hyphen) makes nginx reject the whole config and takes down every project on the machine.

Fix

  • Config.Validate() now checks:
    • host: a valid hostname (letters, digits, inner hyphens, dot-separated, max 253 chars), optionally starting with *.
    • store_code: Magento's own rule, ^[A-Za-z][A-Za-z0-9_]*$. Magento already refuses anything else, so no valid existing store is rejected.
  • magebox domain add validates before saving, so a bad value never reaches .magebox.yaml.
  • RenderStoreMap refuses an unsafe host, code or type as a second line of defence.
  • config-options.md documents the allowed characters, and CHANGELOG.md has an [Unreleased] entry.

Projects that fail validation were already skipped by collectAllProjectConfigs, so one broken project no longer poisons the shared map for the others.

Testing

  • Table-driven tests for valid and invalid hosts and codes (internal/config/store_test.go) and for the render guard (internal/nginx/storemap_test.go)
  • make lint: 0 issues
  • make test: passes

`host` and `store_code` were written unquoted into the nginx store map
that every project shares, and Validate only checked store_type. A
value with a space, semicolon or brace closed the map block and
injected directives into the http context. Even a typo took nginx
down for every project on the machine.

Validate now requires a hostname (optionally with a leading `*.`) and
a store code that follows Magento's own rule. `magebox domain add`
validates before saving, and RenderStoreMap refuses an unsafe entry as
a second line of defence.
@peterjaap
peterjaap merged commit bd57d07 into qoliber:main Nov 12, 2026
10 checks passed
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