<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Intrinsic on Medium]]></title>
        <description><![CDATA[Stories by Intrinsic on Medium]]></description>
        <link>https://medium.com/@intrinsic?source=rss-92706f8dca6c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dQPDBkf9Zu--K_lgK2EJ9A.png</url>
            <title>Stories by Intrinsic on Medium</title>
            <link>https://medium.com/@intrinsic?source=rss-92706f8dca6c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 17 May 2026 03:11:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@intrinsic/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Intrinsic at Google Cloud Next ‘18]]></title>
            <link>https://medium.com/intrinsic-blog/intrinsic-at-google-cloud-next-18-c559eaccde82?source=rss-92706f8dca6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c559eaccde82</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Intrinsic]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 00:39:21 GMT</pubDate>
            <atom:updated>2018-07-23T00:44:51.454Z</atom:updated>
            <content:encoded><![CDATA[<p>In addition to <a href="https://medium.com/intrinsic/come-visit-us-at-node-summit-sf-566a470b8aec">speaking at and sponsoring Node Summit this week</a>, Intrinsic will also speak at Google Cloud Next. We will be showcasing how our runtime enforcement system can protect Google Cloud Functions. Serverless architectures take care of your infrastructure security, so most of the remaining threats are at the application level. Intrinsic is perfect for this: it’s designed to protect your application from developer mistakes, vulnerabilities and malicious code.</p><p>Join us on Wednesday, July 25 at 11 AM, where our CTO Devon Rifkin will take part in a session along with members of the Google Cloud team and npm’s CTO. Devon will demo how Intrinsic protects Google Cloud Functions from various kinds of threats, including attacks from malicious third-party code.</p><p>We hope to see you there!</p><h4><a href="https://cloud.withgoogle.com/next18/sf/sessions/session/156724">How Serverless Helps You Build Highly Scalable and Secure Apps</a></h4><p><strong>Myles Borins</strong>, Developer Advocate, Google Cloud; <strong>Michael McDonald</strong>, Product Manager, Google Cloud; <strong>Devon Rifkin</strong>, CTO, Intrinsic; <strong>C J Silverio</strong>, CTO, npm<br><strong>Wednesday, July 25:</strong> 11–11:50 AM<strong><br>Location:</strong> Palace Hotel, San Francisco| Floor: Level 1 | Room: Gold</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c559eaccde82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intrinsic-blog/intrinsic-at-google-cloud-next-18-c559eaccde82">Intrinsic at Google Cloud Next ‘18</a> was originally published in <a href="https://medium.com/intrinsic-blog">intrinsic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proxies and Reflection in JavaScript]]></title>
            <link>https://medium.com/intrinsic-blog/proxies-and-reflection-in-javascript-334412028f69?source=rss-92706f8dca6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/334412028f69</guid>
            <category><![CDATA[reflections]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[programming-languages]]></category>
            <dc:creator><![CDATA[Intrinsic]]></dc:creator>
            <pubDate>Wed, 25 Apr 2018 16:31:01 GMT</pubDate>
            <atom:updated>2018-10-02T01:01:23.607Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*wZOKqct6slrzkaWsBTvMhQ.png" /><figcaption>Reflection in JavaScript</figcaption></figure><p>Reflection is defined as the ability of a program to inspect and modify its structure and behavior at runtime. In this article we will explore some features of JavaScript related to reflection, and suggest usages for them.</p><h3>Inferring types</h3><p>JavaScript has offered reflection for a long time now, with operators such as typeof and instanceof:</p><ul><li>typeof is used to know the type of an unevaluated value, which can be a primitive or an object (note that functions and arrays are also objects).</li><li>instanceof is used to know if the prototype of a constructor is in an object&#39;s prototype chain. This requires the instanceof operator to evaluate properties from both objects.</li></ul><p>Let’s take a look at instanceof:</p><pre>// Definition of Fruit<br>function Fruit() {<br>  this.isFood = true;<br>};</pre><pre>// Definition of Banana using old-style inheritance<br>function Banana() {<br>  this.name = &#39;Banana&#39;;<br>}</pre><pre>Banana.prototype = Object.create(Fruit.prototype);</pre><pre>// High level inspections<br>const banana = new Banana();<br>console.log(banana instanceof Banana); // true, Banana is a Fruit<br>console.log(banana instanceof Fruit); // true, Fruit is an Object<br>console.log(banana instanceof Object); // true</pre><p>a instanceof B can be oversimplified as B[Symbol.hasInstance](a):</p><pre>console.log(Banana[Symbol.hasInstance](banana)); // true<br>console.log(Fruit[Symbol.hasInstance](banana)); // true<br>console.log(Object[Symbol.hasInstance](banana)); // true</pre><p><em>NOTE: </em><em>Symbol is used to create globally unique values. The reason why symbols are used as identifiers rather than strings is to reduce identifier collisions with user code.</em></p><p>B[Symbol.hasInstance](a) can be understood as traversing the prototype chain of a until B.prototype is found.</p><pre>// mostly equivalent to Banana[Symbol.hasInstance](banana)<br>console.log(<br>  Reflect.get(Banana, ‘prototype’) === (  <br>    Reflect.getPrototypeOf(banana) <br>  )<br>); // true</pre><pre>// mostly equivalent to Fruit[Symbol.hasInstance](banana)<br>console.log(<br>  Reflect.get(Fruit, &#39;prototype&#39;) === (<br>    Reflect.getPrototypeOf(<br>      Reflect.getPrototypeOf(banana)<br>    )<br>  )<br>); // true</pre><pre>// mostly equivalent to Object[Symbol.hasInstance](banana)<br>console.log(<br>  Reflect.get(Object, &#39;prototype&#39;) === (<br>    Reflect.getPrototypeOf(<br>      Reflect.getPrototypeOf(<br>        Reflect.getPrototypeOf(banana)<br>      )<br>    )<br>  )<br>); // true</pre><p><em>NOTE: When I say “mostly equivalent”, is because this an oversimplified version of what the built-in function does according to the ECMAScript spec.</em></p><h3>Altering the behavior of instanceof</h3><p>Now, we know that:</p><ul><li>a instanceof B is expressed in terms of B[Symbol.hasInstance].</li><li>B[Symbol.hasInstance] works by iterating the prototype chain of a.</li></ul><p>We can override the behavior of [Symbol.hasInstance]:</p><pre>class C {<br>  // `x instanceof C` will now be true<br>  static [Symbol.hasInstance](instance) {<br>    return true;<br>  }<br>};</pre><pre>console.log({} instanceof C); // true<br>console.log(Date instanceof C); // true<br>console.log(Promise instanceof C); // true</pre><p>We can also use Proxy to return an alternative prototype, when evaluated through the proxy:</p><pre>const obj = {};<br>const proxy = new Proxy(obj, {<br>  getPrototypeOf: function () {<br>    return Date.prototype;<br>  }<br>})</pre><pre>// prints true<br>console.log(proxy instanceof Date);</pre><pre>// also prints true<br>console.log(Reflect.getPrototypeOf(proxy) === Date.prototype);</pre><h3>More usages of proxies</h3><p>Proxy can be used also to override more fundamental behaviors. Proxies are created like this:</p><pre>new Proxy(target, [traps])</pre><p>The second argument is an object containing handler functions for various operations, these include:</p><ul><li>get/set: getting/setting a property.</li><li>defineProperty/deleteProperty: defining/deleting a property.</li><li>has: overrides behavior of in operator.</li><li>getPrototypeOf/setPrototypeOf: Obtaining or setting an object&#39;s prototype.</li><li>apply/construct: invoking a function, or overriding the new operator.</li><li>ownKeys: obtaining the keys of an object. e.g: Object.keys, Reflect.ownKeys, etc.</li><li>and more…</li></ul><p>Not all operations can be proxied. For instance, support for proxying for..in enumerations was deprecated. This is also the case for iterating over an array with a for loop.</p><h3>Beyond proxies</h3><p>In addition to using proxies, methods named using built-in symbols can be used to override additional fundamental behavior. Among them, we have:</p><ul><li>[Symbol.hasInstance]: explained earlier in the instanceof section.</li><li>[Symbol.iterator]: used by for..of loops and spread syntax.</li><li>[Symbol.toPrimitive]: used to convert the object into a primitive given a type hint argument. Similar to valueOf() (which does not take a hint) and the better known toString().</li></ul><h3>Testing applications</h3><p>Overriding fundamental JavaScript behavior for an object can be useful when testing an application:</p><ul><li>Inspecting a function call in terms of its arguments list or receiver.</li><li>Having detailed information of how and when a property is accessed, defined or deleted.</li><li>Satisfying type constraints without having to go through the process of defining a type or instancing a type.</li></ul><p>There are existing libraries that help with some of these tasks, such as sinon. However, this creates the need for additional dependencies, and while sinon is rather robust, the features mentioned in this article are well integrated into modern JavaScript.</p><p>For example, we can use the following proxy to validate a function call:</p><pre>// Using Node&#39;s `assert` module<br>const assert = require(&#39;assert&#39;);</pre><pre>// Application code<br>const targetObj = {<br>  // targetFn signature is (number, boolean, object) =&gt; number<br>  targetFn: (a, b, c) =&gt; { return 123; }<br>};</pre><pre>// Test code<br>const proxy = new Proxy(targetObj, {<br>  // This handler will run when a property is read from `targetObj`<br>  get: (targetObj, prop, receiver) =&gt; {<br>    const value = Reflect.get(targetObj, prop);</pre><pre>    if (prop !== &#39;targetFn&#39;) {<br>      return value;<br>    }</pre><pre>    return new Proxy(value, {<br>      // This handler will run when targetObj.targetFn() is invoked<br>      // - fn is the function being invoked<br>      // - thisArg is the receiver object<br>      // - args is the arguments list<br>      apply: (fn, thisArg, args) =&gt; {<br>        // Validate that the receiver is an object<br>        assert.ok(thisArg instanceof Object);</pre><pre>        // Validate function argument types<br>        assert.strictEqual(args.length, 3);<br>        assert.strictEqual(typeof args[0], &#39;number&#39;);<br>        assert.strictEqual(typeof args[1], &#39;boolean&#39;);<br>        assert.strictEqual(typeof args[2], &#39;object&#39;);<br>        assert.ok(typeof args[2]);<br>        assert.ok(args[2] instanceof Object);</pre><pre>        // Validate that the results<br>        const result = Reflect.apply(fn, thisArg, args);<br>        assert.strictEqual(result, 123);<br>        return result;<br>      }<br>    });<br>  }<br>});</pre><pre>// Usage<br>proxy.targetFn(1, true, {});</pre><h3>Conclusion</h3><p>JavaScript provides powerful features for examining and modifying objects and their interactions at runtime. In addition to testing, this functionality can be useful when logging, debugging, as well as writing adapters and shims to retain compatibility among versions. I invite you to explore more creative usages for these features.</p><p><em>This article was written by me, Felipe Ortega. I work at a company called Intrinsic where we specialize in writing software for securing Node.js applications using the Least Privilege model. Our product is very powerful and is easy to implement. If you are looking for a way to secure your Node applications, give us a shout at </em><a href="mailto:hello@intrinsic.com"><em>hello@intrinsic.com</em></a><em>.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F098291%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F098291%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6379192ce5d65a7727c1e8974ab2ab2/href">https://medium.com/media/d6379192ce5d65a7727c1e8974ab2ab2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=334412028f69" width="1" height="1" alt=""><hr><p><a href="https://medium.com/intrinsic-blog/proxies-and-reflection-in-javascript-334412028f69">Proxies and Reflection in JavaScript</a> was originally published in <a href="https://medium.com/intrinsic-blog">intrinsic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>