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

XS deep freeze conflicts with SES security constraints #1058

Open
erights opened this issue May 5, 2020 · 14 comments
Open

XS deep freeze conflicts with SES security constraints #1058

erights opened this issue May 5, 2020 · 14 comments
Assignees
Labels
moddable-P2 Moddable collaboration: future priority security vaults_triage DO NOT USE xsnap the XS execution tool

Comments

@erights
Copy link
Member

erights commented May 5, 2020

The XS Object.freeze takes a second optional boolean parameter that, if truthy, causes some form of transitive freezing. But unlike harden, it does more freezing than user code can do (and inspired the petrify notion we're still designing). As currently implemented, this enhanced Object.freeze can be used for attack.


previously:

Moddable-OpenSource/moddable#351
Moddable-OpenSource/moddable#353

are both memory unsafety problems in XS. Let's use this issue thread to accumulate XS issues that are a security concern for us, until we start on an engineering process of securing XS.

Memory unsafety bugs are of course fully fatal for us. But all sorts of other deviations from standard ES, including deviations allowed by the ES spec, are potential concerns:

@erights
Copy link
Member Author

erights commented May 5, 2020

Attn @phoddie

@phoddie
Copy link

phoddie commented May 5, 2020

Thanks for the nudge.

Regarding Object.freeze we are open to options. The feature exists to support preloading. It isn't strictly necessary at runtime. We could make unavailable at runtime or move it off Object so it doesn't automatically propagate into Compartments.

@dckc
Copy link
Member

dckc commented Jan 15, 2021

A few more relevant issues:

@dckc dckc added the xsnap the XS execution tool label Apr 28, 2021
@dckc dckc added this to the XS Memory Safety Audit milestone Jul 21, 2021
@dckc
Copy link
Member

dckc commented Aug 3, 2021

Let's focus this issue on XS deep freeze (Object.freeze(x, true)). I tested that it's outstanding:


function freezeBadArg() {
  'use strict';

  const x = { y: { size: 2 } };
  // @ts-ignore
  Object.freeze(x, true);
  try {
    x.y.color = 'blue';
    return x.y.color;
  } catch (e) {
    return e.message;
  }
}

test('extra Object.freeze arg on node', async t => {
  t.is(freezeBadArg(), 'blue');
});

test('extra Object.freeze arg on XS with SES', async t => {
  const bootScript = await ld.asset('../dist/bundle-ses-boot.umd.js');
  const opts = options(io);
  const vat = xsnap(opts);
  t.teardown(() => vat.terminate());
  await vat.evaluate(bootScript);

  await vat.evaluate(`
    const encoder = new TextEncoder();
    const send = msg => issueCommand(encoder.encode(JSON.stringify(msg)).buffer);
    send((${freezeBadArg})());
  `);
  t.deepEqual(opts.messages, ['"blue"']);
});

I was going to close this, since security-related issues in the moddable repo (Moddable-OpenSource/moddable#351 , Moddable-OpenSource/moddable#353 ) are closed, and other stuff mentioned above is tracked elsewhere, but deep freeze is still an issue.

@dckc dckc changed the title XS security issues XS deep freeze conflicts with SES security constraints Aug 3, 2021
@dckc
Copy link
Member

dckc commented Aug 3, 2021

@erights remind me which SES constraint this violates? i.e. how it can be used for attack?

You explained it to me once but it has since leaked out.

@dckc dckc removed this from the XS Memory Safety Audit milestone Aug 3, 2021
@phoddie
Copy link

phoddie commented Aug 3, 2021

I'm not certain that our extension to Object.freeze changes the security properties of the JavaScript language. The optional behavior implemented effectively performs Object.freeze recursively but does not change what is frozen. For example, private properties are not frozen.

Here's an example to check my understanding:

class Foo {
	#x = 12;
	y = {z: 12};
	
	set x(value) {
		this.#x = value;
	} 
	get x() {
		return this.#x;
	} 
}

let f = new Foo;
Object.freeze(f, true);
f.x = 11;
trace(f.x, "\n");
f.y.z = 12;

Setting f.x succeeds, with the following trace outputting 11 . Setting f.y.z throws because z is not writable.

Even if it is "safe", this extension to Object.freeze is not beneficial to Agoric's use of XS. Perhaps we should make it an optional feature that can be compiled in/out at build time, so that it doesn't need to be a consideration in the runtime?

Note: When building a ROM image, the XS linker does perform a deeper freeze that goes beyond what can be expressed by the JavaScript language today. But, that feature of XS is not used by the Agoric runtime.

@dckc
Copy link
Member

dckc commented Aug 4, 2021

...
Even if it is "safe", this extension to Object.freeze is not beneficial to Agoric's use of XS. Perhaps we should make it an optional feature that can be compiled in/out at build time, so that it doesn't need to be a consideration in the runtime?

That seems cost-effective. Yes, please, @phoddie

@erights
Copy link
Member Author

erights commented Aug 4, 2021

I would love to understand its semantics. If it is approximately harden or purify, it may be great for us! Though we would package it differently.

@dckc dckc added the moddable-P2 Moddable collaboration: future priority label Sep 9, 2021
@dckc dckc added this to the XS Memory Safety Audit milestone Sep 10, 2021
@dckc dckc added the MN-1 label Jan 20, 2022
@dckc dckc removed their assignment Jan 26, 2022
@erights erights removed the MN-1 label Jan 28, 2022
@erights
Copy link
Member Author

erights commented Jan 28, 2022

I removed the MN-1 label because this does not affect MN-1.

@erights
Copy link
Member Author

erights commented Jan 28, 2022

Oh, I should have noticed @dckc that you added the MN-1 label recently. If I'm missing something, please add it back in and let me know. Thanks.

@dckc
Copy link
Member

dckc commented Jan 28, 2022

Right... It's more MN-3.

@Tartuffo Tartuffo added the MN-1 label Feb 2, 2022
@Tartuffo
Copy link
Contributor

Tartuffo commented Feb 3, 2022

@kriskowal This does not have an area label that is covered by our weekly tech / planning meetings. Can you assign the proper label? We cover: agd, agoric-cosmos, amm, core economy, cosmic-swingset, endo, getrun, governance, installation-bundling, metering, run-protocol, staking, swingset, swingset-runner, token economy, wallet, zoe contract.

@dckc
Copy link
Member

dckc commented Feb 3, 2022

Again, I suggest xsnap is covered in weekly endo / SES meetings.

@Tartuffo
Copy link
Contributor

Tartuffo commented Feb 3, 2022

Agreed, I just added it to the ZH filter for the Zoe/ERTP meeting.

@Tartuffo Tartuffo removed the MN-1 label Feb 7, 2022
@Tartuffo Tartuffo removed this from the XS Memory Safety Audit milestone Feb 8, 2022
@Tartuffo Tartuffo added this to the Mainnet 1 milestone Mar 23, 2022
@Tartuffo Tartuffo modified the milestones: Mainnet 1, RUN Protocol RC0 Apr 5, 2022
@Tartuffo Tartuffo removed this from the Mainnet 1 RC0 milestone Aug 10, 2022
@ivanlei ivanlei added the vaults_triage DO NOT USE label Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
moddable-P2 Moddable collaboration: future priority security vaults_triage DO NOT USE xsnap the XS execution tool
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants