Skip to content

fix: use meta.json worldName for maptool uploads#403

Merged
fank merged 2 commits into
mainfrom
fix/maptool-upload-worldname
Apr 27, 2026
Merged

fix: use meta.json worldName for maptool uploads#403
fank merged 2 commits into
mainfrom
fix/maptool-upload-worldname

Conversation

@fank
Copy link
Copy Markdown
Member

@fank fank commented Apr 27, 2026

Summary

  • Maptool uploads were saving maps under names like ocap-maptool-uploads-1517127726-1777287006640 instead of the actual world name (e.g. stratis) when users zipped the contents of a grad_meh export directory rather than the directory itself.
  • Root cause: handler_maptool.go derived worldName from the basename of the extraction directory via WorldNameFromDir. When meta.json and sat/ sit at the zip root, FindGradMehDir returns the temp extraction dir, whose basename is the temp-dir name. That name was then used to create mapsDir/<worldName> and the job ID before the pipeline's parse_gradmeh stage corrected job.WorldName from meta.json.
  • Fix: read meta.json upfront in the handler via ReadGradMehMeta and submit the authoritative worldName to the job manager.

Test plan

  • Upload a zip containing the stratis/ folder — saved as stratis (regression check)
  • Upload a zip with meta.json + sat/ at the root — saved as stratis (the bug case)
  • Upload a zip without a valid meta.json — returns a clear 400 error

When users zip the contents of a grad_meh export directory directly
(meta.json and sat/ at the zip root), the world name was derived from
the temp extraction directory's basename, producing names like
"ocap-maptool-uploads-1517127726-1777287006640" instead of "stratis".

Read worldName from meta.json upfront so the authoritative value is
used for the output directory and job ID before the pipeline runs.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the map tool import handler to read world metadata from a meta.json file instead of deriving the world name from the directory. Feedback highlights a potential visibility issue with the new ReadGradMehMeta function and a critical path traversal vulnerability where the user-provided world name is used without validation.

Comment thread internal/server/handler_maptool.go
Comment thread internal/server/handler_maptool.go
Prevent path traversal when meta.json's worldName is used to construct
the output directory under mapsDir. Restrict to [a-z0-9_-] and reject
path separators and traversal segments.
@fank fank force-pushed the fix/maptool-upload-worldname branch from b435c62 to d7c579f Compare April 27, 2026 11:59
@fank
Copy link
Copy Markdown
Member Author

fank commented Apr 27, 2026

Addressed gemini-code-assist review:

  • ReadGradMehMeta/GradMehMeta not exported (comment on line 147) — false positive. Both are exported in internal/maptool/worldmeta.go; the bot likely confused them with the unexported worldMetaJSON helper in metadata.go. Build and tests pass.
  • Path traversal via worldName (comment on line 152) — fixed in d7c579f. Added validation inside ReadGradMehMeta itself (so all callers benefit) that rejects path separators, traversal segments, and anything outside [a-z0-9_-].

@github-actions
Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/web/internal/maptool 94.97% (-0.21%) 👎
github.com/OCAP2/web/internal/server 94.08% (-0.16%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/web/internal/maptool/worldmeta.go 90.91% (-9.09%) 44 (+10) 40 (+6) 4 (+4) 👎
github.com/OCAP2/web/internal/server/handler_maptool.go 88.97% (-1.25%) 136 (+3) 121 (+1) 15 (+2) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

@fank fank merged commit c10bbab into main Apr 27, 2026
2 checks passed
@fank fank deleted the fix/maptool-upload-worldname branch April 27, 2026 12:20
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