Skip to content

describedByMetaHashConstantString cannot run under this repo's fs_permissions, and interpolates its name into the path unsanitised #45

Description

@thedavidmeister

LibCodeGen.describedByMetaHashConstantString reads from meta/:

bytes memory describedByMeta = vm.readFileBinary(string.concat("meta/", name, ".rain.meta"));

This repo's foundry.toml grants read on foundry.toml and read-write on src/generated, and nothing else. So the function cannot run here at all. Reproduced against c72eb89 — the call reverts:

vm.readFileBinary: the path meta/CodeGennable.rain.meta is not allowed to be accessed for read operations

A consumer needs { access = "read", path = "meta" } for this function to work, and nothing in the README, the NatSpec or foundry.toml says so. There is also no test in the repo that reaches it, which is why the gap survived.

Second defect in the same line

name is interpolated into the path unsanitised, so it can traverse: describedByMetaHashConstantString(vm, "../src/generated/X") reads src/generated/X.rain.meta. Same shape as #38 for LibFs.pathForContract, and the same one-line fix — reject a name that is not a plain identifier.

Note this traversal is the mechanism the accompanying coverage PR's happy-path tests use to reach the function at all, given the permission grant above. A reviewer should see that rather than discover it.

Consequence for the wider grant

Because this function forces a consumer to widen fs_permissions beyond src/generated, it also widens what #38's unvalidated contract name can reach. The two interact: a repo that adopts describedByMetaHashConstantString is a repo where LibFs's path traversal stops being blocked by config.

Triage framing

meta/ may be a convention every consumer of this package already follows, in which case the fix is documenting the required permission rather than changing the code. It is also possible this function is unused and should be removed — nothing in this repo calls it, and script/Build.sol does not.

Either way the current state is a published library function that fails under its own repo's configuration with an error naming a permission rather than a missing convention.

Metadata

Metadata

Labels

adversarialAdversarial mutation-test findingauditAudit finding

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions