
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
aran-access-control
Advanced tools
AranAccessControl is npm module that implements an access control system around JavaScript code instrumented by Aran. This module's motivation is to build dynamic analyses capable of tracking primitive values across the object graph.
npm install acorn aran astring aran-access-control
const Acorn = require("acorn");
const Aran = require("aran");
const Astring = require("astring");
const AranAccessControl = require("aran-access-control");
const aran = Aran({namespace:"TRAPS", sandbox:true});
const instrument = (script, parent) =>
Astring.generate(aran.weave(Acorn.parse(script), pointcut, parent));
let counter = 0;
const access = AranAccessControl({
instrument: instrument,
enter: (value) => ({concrete:value, shadow:"#"+(counter++)}),
leave: (value) => value.concrete
});
const pointcut = Object.keys(access.advice);
global.TRAPS = Object.assign({}, access.advice);
global.TRAPS.primitive = (primitive, serial) => {
const result = access.advice.primitive(primitive, serial);
console.log(result.shadow+"("+result.concrete+") // @"+serial);
return result;
};
global.TRAPS.binary = (operator, left, right, serial) => {
const result = access.advice.binary(operator, left, right, serial);
console.log(result.shadow+"("+result.concrete+") = "+left.shadow+" "+operator+" "+right.shadow+" // @"+serial);
return result;
};
global.eval(Astring.generate(aran.setup()));
global.eval(instrument(`
let division = {};
division.dividend = 1 - 1;
division.divisor = 20 - 2 * 10;
division.result = division.dividend / division.divisor;
if (isNaN(division.result))
console.log("!!!NaN division result!!!");
`));
#6(apply) // @2
#10(defineProperty) // @2
#14(getPrototypeOf) // @2
#18(keys) // @2
#22(iterator) // @2
#24(undefined) // @2
#26(dividend) // @6
#27(1) // @9
#28(1) // @10
#29(0) = #27 - #28 // @8
#30(divisor) // @12
#31(20) // @15
#32(2) // @17
#33(10) // @18
#34(20) = #32 * #33 // @16
#35(0) = #31 - #34 // @14
#36(result) // @20
#37(dividend) // @23
#38(divisor) // @25
#39(NaN) = #29 / #35 // @22
#42(result) // @30
#45(log) // @33
#46(!!!NaN division result!!!) // @35
!!!NaN division result!!!

access = require("aran-access-control")(membrane)membrane :: object
inner = membrane.enter(tame):
User-defined function to convert a tame value to an inner value.tame = membrane.leave(inner):
User-defined function to convert an inner value to a tame value.instrumented = membrane.instrument(code, serial):
This function will be called to transforms code before passing it to the infamous eval function.
code :: stringserial :: numberinstrumented :: stringaccess :: object
access.advice :: object
An aran advice, contains Aran traps and a SANDBOX field which is set to access.capture(global).
The user can modify the advice before leting aran using it.access.membrane :: object:
The same object as the membrane arguments.tame = access.capture(wild)
Convert a wild value into a tame value.wild = access.release(tame):
Convert a tame value into a wild value.Aran and program instrumentation in general is good for introspecting the control flow and pointers data flow.
Things become more difficult when reasoning about primitive value data flow is involved.
For instance, there is no way at the JavaScript language level to differentiate two null values even though they have different origins.
This restriction strikes every JavaScript primitive values because they are inlined into different parts of the program's state -- e.g the environment and the value stack.
All of these copying blur the concept of a primitive value's identity and lifetime.
By opposition, objects can be properly differentiated based on their address in the store.
Such situation happens in almost every mainstream programming languages.
We now discuss several strategies to provide an identity to primitive values:
undefined and null cannot be tracked by this method, boxed values do not always behave like their primitive counterpart within builtins.
// Strings cannot be differentiated based on their origin
let string1 = "abc";
let string2 = "abc";
assert(string1 === string2);
// Boxed strings can be differentiated based on their origin
let boxed_string1 = new String("abc");
let boxed_string2 = new String("abc");
assert(boxed_string1 !== boxed_string2);
// Boxed value behave as primitive in some builtins:
assert(JSON.stringify({a:string1}) === JSON.stringify({a:boxed_string1}));
// In others, they don't...
let error
try {
Object.defineProperty(string1, "foo", {value:"bar"});
} catch (e) {
error = e;
}
assert(error);
Object.defineProperty(boxed_string1, "foo", {value:"bar"});
valueOf Method:
A similar mechanism to boxed value is to use the valueOf method.
Many JavaScript builtins expecting a primitive value but receiving an object will try to convert this object into a primitive using its valueOf method.
As for boxed values this solution is not bullet proof and there exists many cases where the valueOf method will not be invoked.I'm Laurent Christophe a phd student at the Vrij Universiteit of Brussel (VUB). I'm working at the SOFT language lab in close relation with my promoters Coen De Roover and Wolfgang De Meuter. I'm currently being employed on the Tearless project.
FAQs
Access Control System for Aran
The npm package aran-access-control receives a total of 6 weekly downloads. As such, aran-access-control popularity was classified as not popular.
We found that aran-access-control demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.