Skip to content

Commit

Permalink
chore: harden the promise-space Proxy targets
Browse files Browse the repository at this point in the history
per @erights: this prevents non-get operations from mutating the
target and using it as a communications channel.
  • Loading branch information
warner committed May 12, 2023
1 parent eec0147 commit 876c16d
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions packages/vats/src/core/promise-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,21 @@ export const makePromiseSpace = (optsOrLog = {}) => {

/** @type {PromiseSpaceOf<T>['consume']} */
// @ts-expect-error cast
const consume = new Proxy(
{},
{
get: (_target, name) => {
assert.typeof(name, 'string');
return provideState(name).pk.promise;
},
const consume = new Proxy(harden({}), {
get: (_target, name) => {
assert.typeof(name, 'string');
return provideState(name).pk.promise;
},
);
});

/** @type {PromiseSpaceOf<T>['produce']} */
// @ts-expect-error cast
const produce = new Proxy(
{},
{
get: (_target, name) => {
assert.typeof(name, 'string');
return makeProducer(name);
},
const produce = new Proxy(harden({}), {
get: (_target, name) => {
assert.typeof(name, 'string');
return makeProducer(name);
},
);
});

return harden({ produce, consume });
};
Expand Down

0 comments on commit 876c16d

Please sign in to comment.