Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You cannot stop the variable <code>g1</code> from being reassigned on all browsers. Some browsers would allow you to define <code>g1</code> as a <a href="https://developer.mozilla.org/en/JavaScript/Reference/Statements/const" rel="nofollow noreferrer">constant</a> thus:</p> <pre><code>const g1 = G(f1); </code></pre> <p>which would prevent the name <code>g1</code> from being rebound, and you can use <code>Object.defineProperty</code> to define a <a href="https://stackoverflow.com/questions/366047/can-read-only-properties-be-implemented-in-pure-javascript">read-only</a> global property of <code>window</code> on others, but in general, there are no <code>const</code> definitions in JavaScript.</p> <p>To make it clearer, consider two scenarios:</p> <p>(1) An attacker can run code in the scope in which <code>f1</code> is declared, and then other code reads <code>f1</code>.</p> <pre><code>var f1 = ...; // You define f1 f1 = function () { return false; }; // Attacker code runs doSomethingWith(f1()); // Naive code reads f1 and calls it. </code></pre> <p>The attacker succeeds in this case in confusing the naive code because they changed the value at <code>f1</code>.</p> <p>(2) An attacker runs code in the scope after <code>f1</code> has been read.</p> <pre><code>var f1 = ...; // You define f1 // Cautious code reads and stores f1 in a safe place for later use. (function () { var f = f1; setTimeout(0, function () { doSomethingWith(f()); }); })(); f1 = function () { return false; }; // Attacker code runs. </code></pre> <p>The attacker fails in this case because the cautious code read the value of <code>f1</code> before the attacker changed the value stored at <code>f1</code>, so the private <code>f</code> continues to return <code>true</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload