-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: secure the console and nestedEvaluate endowments
We need to evaluate their wrappers in the SES root realm so that their prototype chain can't be abused to escape into the primal realm.
- Loading branch information
1 parent
d39c827
commit ed13e80
Showing
3 changed files
with
73 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
// We assume we're running in a SES environment. | ||
export function makeConsole(baseConsole) { | ||
// We restrict `console` to the API that can be implemented | ||
// by the anylogger API. | ||
// It should be unobservable by the code using it, notably | ||
// only send output via the base console, and don't return a value. | ||
const console = {}; | ||
for (const level of ['debug', 'log', 'info', 'warn', 'error']) { | ||
console[level] = (...args) => { | ||
baseConsole[level](...args); | ||
return undefined; | ||
}; | ||
} | ||
return harden(console); | ||
} | ||
|
||
// This function implements makeConsole with SES1 (pre-lockdown). | ||
export function SES1MakeConsole(SES1, baseConsole) { | ||
// We evaluate within SES so that the resulting object does | ||
// not give away access to the root realm. | ||
const source = `(${makeConsole})`; | ||
const myConsole = SES1.evaluate(source, { | ||
harden: SES1.global.SES.harden, | ||
})(baseConsole); | ||
return myConsole; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import harden from '@agoric/harden'; | ||
|
||
// We assume we're running in a SES environment. | ||
export function makeNestedEvaluate(compartment, endowments = {}) { | ||
// Create a simple wrapper for the evaluator. | ||
const nestedEvaluate = source => compartment.evaluate(source, endowments); | ||
|
||
// Feed back the endowment to itself. | ||
endowments.nestedEvaluate = nestedEvaluate; | ||
return harden(nestedEvaluate); | ||
} | ||
|
||
// This function implements makeNestedEvaluate with SES1 (pre-lockdown). | ||
export function SES1MakeNestedEvaluate(SES1, endowments = {}) { | ||
// We evaluate within SES so that the resulting object does | ||
// not give away access to the root realm. | ||
const source = `(${makeNestedEvaluate})`; | ||
const nestedEvaluate = SES1.evaluate(source, { | ||
harden: SES1.global.SES.harden, | ||
})(SES1, endowments); | ||
return nestedEvaluate; | ||
} |