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

feat(compartment-mapper): Validate compartment maps #1085

Merged

Conversation

kriskowal
Copy link
Member

Fixes: #601
Refs: Agoric/agoric-sdk#3859

This change adds validation for compartment map input from archives.

This design sacrifices schema evolution for a tight correspondence between the content of a compartment map and its consistent hash. The validator allows for nothing extra. This may become a hindrance, in which case we would need to relax the extra property assertions and closed ranges for some types. For now, this is conservative in order to provide the maximum assurance to the authors.

@kriskowal kriskowal self-assigned this Feb 18, 2022
@kriskowal kriskowal added endo enhancement New feature or request confinement Pertaining to confinement of guest programs. labels Feb 18, 2022
@kriskowal kriskowal force-pushed the agoric-3859-hash-bundle-compartment-map-validation branch 2 times, most recently from dd5588f to a7702d8 Compare February 18, 2022 05:03
Copy link
Contributor

@warner warner left a comment

Choose a reason for hiding this comment

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

Looks good

@@ -164,12 +165,11 @@ export const parseArchive = async (
}

const compartmentMapText = textDecoder.decode(compartmentMapBytes);
const compartmentMap = /** @type {CompartmentMapDescriptor} */ (parseLocatedJson(
const compartmentMap = parseLocatedJson(
Copy link
Contributor

Choose a reason for hiding this comment

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

I might have asked this before, but do our specs say anything about repeated keys in JSON? That would be a way for two different readers to interpret the same compartment map in divergent ways. If TC39 doesn't have a stance, we might want to add a note to the docs around this hashing/security stuff, that correctness depends upon consistent behavior of everybody's JSON.parse.

Copy link
Member Author

Choose a reason for hiding this comment

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

JSON (ECMA 404) has no position on repeated keys, but JS (ECMA 262) takes the position that JSON gets evaluated as a JS expression if it parses according to 404, such that the last property defined with the one key wins. So, as long as everyone uses JS, they’ll arrive at the same interpretation.


const { compartment, ...extra } = scope;
assert(
Object.keys(extra).length === 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm tempted to suggest this assertNoExtra(extra, explanation) pattern be factored out so the calls fit on a single line, but I think I'm just feeling grumpy towards prettier's verbosity today. The work this file is doing is completely straightforward.

@kriskowal kriskowal force-pushed the agoric-3859-hash-bundle-compartment-map-validation branch from a7702d8 to a46fb2c Compare February 19, 2022 00:00
@kriskowal kriskowal force-pushed the agoric-3859-hash-bundle-compartment-map-validation branch from a46fb2c to 4204058 Compare February 19, 2022 00:04
@kriskowal kriskowal merged commit 3b1800b into master Feb 19, 2022
@kriskowal kriskowal deleted the agoric-3859-hash-bundle-compartment-map-validation branch February 19, 2022 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confinement Pertaining to confinement of guest programs. endo enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compartment mapper: validate compartment map JSON
2 participants