Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vstorage)!: Enforce path validation #8348

Merged
merged 3 commits into from
Sep 19, 2023

Conversation

gibson042
Copy link
Member

Fixes #8337

Description

Improves the cross-referenced Go and JS documentation of vstorage path structure, and updates the Go code to correctly enforce it.

Security Considerations

This change means that vat storage keys are no longer generally valid in vstorage paths, but that is acceptable because they are now stored in the swingset module rather than in vstorage.

Scaling Considerations

There should be a small but largely irrelevant improvement in the performance of validating paths, which are now scanned only once if valid.

Documentation Considerations

n/a

Testing Considerations

Nothing should be needed beyond the included unit tests.

Upgrade Considerations

Existing tests should validate the assumption that vat storage keys are not used in vstorage paths.

Comment on lines +55 to +56
var pathPattern = fmt.Sprintf(`^$|^%[1]s(%[2]s%[1]s)*$`, pathSegmentPattern, pathSeparatorPattern)
var pathMatcher = regexp.MustCompile(pathPattern)
Copy link
Member

Choose a reason for hiding this comment

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

Have we considered instead of building this complex RegExp to split the path and validate each segment with an anchored pathSegmentPattern ? I'm not sure how efficient golang is at creating string slices.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not bad, but I prefer this single-pass approach.

Comment on lines 31 to 32
return func(ctx sdk.Context, pathSegments []string, req abci.RequestQuery) (res []byte, err error) {
switch pathSegments[0] {
Copy link
Member

Choose a reason for hiding this comment

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

Ok this is confusing. I see pathSegment is a / delimited part of the URL's path. At first I thought it was a . delimited vstorage path segment.

I'm not sure how to make this more clear, but right now it isn't sufficiently different. At the very least maybe we should use the "component" nomenclature for vstorage paths? But maybe we could prefix the variables with route/storage as appropriate here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've clarified by renaming to better distinguish URL path vs. vstorage entry path.

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

Thanks for making these clarifications

@gibson042 gibson042 force-pushed the gibson-8337-vstorage-path-validation branch from 4214f34 to 1d12459 Compare September 19, 2023 01:42
@gibson042 gibson042 added the automerge:rebase Automatically rebase updates, then merge label Sep 19, 2023
@mergify mergify bot merged commit dafc7c1 into master Sep 19, 2023
80 checks passed
@mergify mergify bot deleted the gibson-8337-vstorage-path-validation branch September 19, 2023 02:30
mhofman pushed a commit that referenced this pull request Nov 8, 2023
…tion

fix(vstorage)!: Enforce path validation
mhofman pushed a commit that referenced this pull request Nov 10, 2023
…tion

fix(vstorage)!: Enforce path validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vstorage module path validation regular expression is incorrect
2 participants