Zum Hauptinhalt springen
LIVE
CVSS 6.9CVE-2026-137684 | A security flaw has been discovered in eosphoros-ai DB-GPT up to 0.8.3. This affects the function editor_sql_run of the file packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/editor/api_editor_v1.py of the component Editor SQL Run API. Performing a manipulation of the argument db_name results in authorization bypass. It is possible to initiate the attack remotely. The exploit has been released to the public and may be used for attacks. The pull request to fixCVSS 8.7CVE-2026-137992 | libexpat through 2.11.0 contains a denial of service vulnerability in defineAttribute() of lib/xmlparse.c that fails to detect duplicate non-ID #IMPLIED or #REQUIRED attribute declarations. Attackers can supply a crafted XML document with repeated ATTLIST declarations in an internal DTD subset to cause quadratic CPU consumption in storeAtts() during parsing.CVSS 8.5CVE-2026-137994 | Leo through 6.8.10 contains an insecure deserialization vulnerability that allows attackers to execute code by embedding pickled data in unknown XML attributes of .leo outlines. Attackers can place a pickle __reduce__ gadget in a or element attribute that resolveUa passes to pickle.loads, executing code with user privileges when the outline is opened.CVSS 7.0CVE-2026-137995 | FOG Project before 1.6.0.119 contains an information disclosure vulnerability that allows unauthenticated attackers to obtain host tokens from status/hostgetkey.php by supplying a host MAC address. Attackers can present the token to service/hostinfo.php to retrieve decrypted Active Directory join credentials and Windows product keys during deployment windows.CVSS 6.8CVE-2026-137996 | Zettlr before 4.11.0 fails to validate URI schemes in Markdown link targets, allowing attackers to launch arbitrary registered protocol handlers via Electron shell.openExternal without confirmation. Attackers can craft documents whose Ctrl/Cmd-clicked links use smb:// to leak NTLM credential hashes on Windows or invoke custom protocol handlers with attacker-controlled parameters.CVSS 8.5CVE-2026-137997 | HCIPy through 0.7.1 contains an insecure deserialization vulnerability that allows attackers to execute code by supplying crafted .pkl files to read_field, read_grid or read_mode_basis. Because hcipy/util/io.py selects pickle by file extension and calls pickle.load, a __reduce__ gadget in a pupil, apodizer, PSF or mode-basis file runs code with the user's privileges.CVSS 8.5CVE-2026-137998 | Detoxify 0.5.3 through 0.5.4 contains an insecure deserialization vulnerability in load_checkpoint that allows attackers to execute code by supplying a crafted checkpoint file. Attackers can embed a pickle __reduce__ gadget in a .ckpt file loaded via torch.load with weights_only=False to run code with the user's privileges.CVSS 8.5CVE-2026-137999 | JSONSchema2PoPo2 through 3.0.3 contains a code injection vulnerability that allows attackers to inject Python code by supplying JSON Schema default or format values that are written unescaped. Attackers can place a single quote in a string property default to break out of the literal in the generated __init__ signature, executing injected code when the generated module is imported.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

# Understanding JavaScript Closures Through Call Stack, Heap Memory & `[[Scopes]]`

Closures aren't magic—they're simply JavaScript's way of keeping data alive when a function still needs it. Every JavaScript developer has heard statements l…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 4 Min. Lesezeit
Quelle: dev.to
Rubrik: Programmazione sicura

Closures aren't magic—they're simply JavaScript's way of keeping data alive when a function still needs it.




Every JavaScript developer has heard statements like:




  • "A closure is a function that remembers variables from its outer scope."

  • "The inner function closes over variables."

  • "Closures preserve the lexical environment."



But...




  • How does a function actually remember variables?

  • Where are those variables stored after the outer function finishes?

  • Why doesn't JavaScript delete them?



Let's go beyond the textbook definition and see what actually happens inside the JavaScript engine.









The Two Main Players Inside the JavaScript Engine



Whenever a function executes, two important memory areas are involved:




  • Call Stack

  • Heap Memory



Understanding closures is really about understanding where JavaScript stores variables and why some of them survive after a function finishes executing.









1. What Happens in a Normal Function?



Consider a simple function:




function greet() {
let name = "JavaScript";
console.log(name);
}

greet();






When greet() executes:




  1. An Execution Context is created.

  2. Local variables (name) belong to that execution.

  3. The execution context is pushed onto the Call Stack.




Call Stack

┌─────────────────────────┐
│ Execution Context │
│ name = "JavaScript" │
└─────────────────────────┘






After the function finishes:




  • The execution context is popped off the stack.

  • No code references name anymore.

  • It becomes eligible for Garbage Collection.



Everything is cleaned up.









2. What Changes When a Closure Is Created?



Now look at this example:




function outerFunction() {

let count = 0;

function innerFunction() {
count++;
console.log(count);
}

return innerFunction;
}

const counter = outerFunction();

counter();
counter();
counter();






Output




1
2
3






But wait...



outerFunction() already finished executing.



Its execution context has been removed from the Call Stack.



So why is count still available?



That's where closures come in.









Behind the Scenes



When JavaScript notices that innerFunction uses count, it understands:




"This variable will still be needed after outerFunction() returns."




Instead of letting count disappear with the execution context, the engine keeps it alive.



Three important things happen behind the scenes.









Step A — Captured Variables Are Kept in Heap Memory



The variables that are captured by an inner function are stored inside an internal object called the Lexical Environment (often called the Closure Context).



Conceptually, you can think of it like this:




Heap Memory

Lexical Environment

{
count: 0
}






Unlike the Call Stack, heap memory isn't destroyed when the function returns.



This allows the captured variables to stay alive.




Note: Engines don't literally "move" variables from the stack to the heap. Instead, captured variables are stored in a heap-allocated lexical environment so they can outlive the function call.










Step B — The Secret Link ([[Scopes]])



Every function internally carries a hidden reference called:




[[Scopes]]






This hidden reference points to the lexical environment containing the variables it needs.



Conceptually:




counter
│
▼
[[Scopes]]
│
▼
Lexical Environment
{
count: 0
}






Even after outerFunction() has finished, the returned function still knows exactly where count lives.









Step C — The Scope Chain



Later, when you execute:




counter();






JavaScript performs variable lookup in this order:




  1. Check the function's local scope.

  2. If not found, follow [[Scopes]].

  3. Search the lexical environment.

  4. Continue upward until the variable is found.



This lookup process is called the Scope Chain.









Visualizing the Entire Process






Before outerFunction() Returns






Call Stack

┌────────────────────────────┐
│ outerFunction() │
│ count = 0 │
│ innerFunction() │
└────────────────────────────┘












After Returning






Call Stack

┌──────────────────────┐
│ Global Execution │
└──────────────────────┘


Heap Memory

┌────────────────────────┐
│ Lexical Environment │
│ count = 0 │
└────────────────────────┘

▲
│
[[Scopes]]
│
▼

innerFunction






The execution context is gone.



The variable survives because the returned function still references it.









A Simple Analogy



Imagine:





  • outerFunction() is a hotel room.


  • count is an important document.

  • Before checking out, you place the document in a secure locker (Heap Memory).

  • You hand the locker key ([[Scopes]]) to your child (innerFunction).



Even after the hotel room is empty, your child still has the key and can access the document whenever needed.



That's exactly how closures work.









Why Are Closures Useful?






1. Data Privacy



Closures let you create private variables.




function createCounter() {

let count = 0;

return {
increment() {
count++;
},

getCount() {
return count;
}
};
}






Nobody outside can directly modify count.









2. Maintaining State



Closures allow functions to remember information between calls.




const counter = outerFunction();

counter();
counter();
counter();






The value of count persists without using global variables.









Key Takeaways



✔ A closure is created when an inner function uses variables from its outer scope.



✔ JavaScript keeps those captured variables alive inside a heap-allocated lexical environment.



✔ The returned function stores a hidden reference called [[Scopes]] to that environment.



✔ As long as the function exists, the captured variables cannot be garbage collected.



✔ Variable lookup through these linked environments is called the Scope Chain.









Final Thought



Closures aren't magic.



They're simply the JavaScript engine preserving the variables that are still needed.



Once you understand the relationship between the Call Stack, Heap Memory, Lexical Environment, and the hidden [[Scopes]] reference, closures become one of the most elegant and powerful features of JavaScript.

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Discussione della community e commenti

🌐 Entra nella chat principale

Avvia la discussione nel flusso broadcast della Social Chat oppure invia qui sopra un contributo esperto tramite il modulo di integrazione.

Valutazione della community & prova sociale
⭐ Giudizio dei lettori
–
Ø / 5.0
Ancora nessuna valutazione dei lettori
Questo articolo ti è stato utile?
0
Lascia ora la tua valutazione
Valutazione dettagliata (facoltativa)
Contenuto & qualità
Fonte & credibilità
Attualità
Briefing di sicurezza Gratuito · disdetta in 1 clic

Intelligence Digest — gratuito

Ogni giorno le notizie di sicurezza più importanti · annullabile in qualsiasi momento

Cluster di storie correlate & fonti (IA vettoriale)

2 Cluster
2 fonti
OpenAI counter-sues Apple over trade secret theft
AppleInsider News 57 min. fa
1 altra fonte
Articoli simili
🔍 Verwandte News

Auch interessante Nachrichten # Understanding JavaScript Closures Through Call Stack, Heap Memory & `[[Scopes]]`

Thematisch verwandte Begriffe: Understanding, JavaScript, Closures, Through · 6 Treffer

Laden...

Caricamento dei video ...

Laden...

Caricamento degli articoli ...

Laden...

Caricamento dei video ...

Laden...

Caricamento degli articoli ...

Laden...

Caricamento dei video ...

Laden...

Caricamento degli articoli ...

Laden...

Caricamento dei video ...

Laden...

Caricamento degli articoli ...

Laden...

Caricamento dei video ...

💬 Caricamento dei commenti…
Trascina per aggiornare
Widgets & Topics
Loading widgets…
Nächster Beitrag