Impact of Frameworks on Security of JavaScript applications

Dr. Ksenia Peguero (Senior Manager of Research Engineering · Synopsis Software Integrity Group)

Swiss Cyber Storm 2021 · Day 1 · Arena

Overview

In this insightful talk from Swiss Cyber Storm, Dr. Ksenia Peguero, a Senior Manager of Research Engineering at Synopsis Software Integrity Group, presented her extensive PhD research on the profound impact of JavaScript frameworks on the security posture of applications. Her presentation delved into how the architectural choices, built-in features, and default configurations of popular JavaScript frameworks directly influence the prevalence and mitigation of common vulnerabilities like Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) across client-side, server-side, and desktop applications.

Watch on YouTube · Slides

Visual summary for Impact of Frameworks on Security of JavaScript applications by Dr. Ksenia Peguero
Visual summary for Impact of Frameworks on Security of JavaScript applications by Dr. Ksenia Peguero

Key moments

  1. 2:52 Why developers often overlook framework security choices.
  2. 4:15 Five levels of vulnerability mitigation in software.
  3. 9:50 Built-in Angular.js XSS protection proved highly effective.
  4. 13:20 Meteor's websocket design inherently prevents CSRF attacks.
  5. 17:50 Framework security defaults are critically important for protection.
  6. 21:00 Electron's node integration and context isolation defaults.
  7. 24:00 Speaker's VS Code plugin for Electron security issues.
  8. 28:00 Auditors' role in assessing framework security early on.

Impact of Frameworks on Security of JavaScript applications

Speakers: Dr. Ksenia Peguero, Senior Manager of Research Engineering, Synopsis Software Integrity Group

Conference: Swiss Cyber Storm

YouTube: https://www.youtube.com/watch?v=r4jGo-IQmJw

Overview

In this insightful talk from Swiss Cyber Storm, Dr. Ksenia Peguero, a Senior Manager of Research Engineering at Synopsis Software Integrity Group, presented her extensive PhD research on the profound impact of JavaScript frameworks on the security posture of applications. Her presentation delved into how the architectural choices, built-in features, and default configurations of popular JavaScript frameworks directly influence the prevalence and mitigation of common vulnerabilities like Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) across client-side, server-side, and desktop applications.

Dr. Peguero's research is particularly timely given JavaScript's perennial status as the most popular programming language. Developers, when selecting frameworks, often prioritize functionality, performance, and community support over inherent security capabilities. This talk challenged that paradigm, proposing that integrating security measures closer to the framework—or even into its fundamental design—can significantly reduce the likelihood of developers introducing security flaws, aligning with the "shift-left" security philosophy. The presentation explored various levels of security mitigation, from custom developer code to framework-level design, offering empirical data to support the hypothesis that framework-provided security is often the most effective.

Background

▶ Watch: Why developers often overlook framework security choices. (2:52)

JavaScript has held the top spot as the most popular programming language for many years, a trend confirmed by Octoverse reports since 2014. Its ubiquity has led to an explosion of frameworks, with options available for virtually any application type: client-side (e.g., Angular, React, Vue), server-side (e.g., Express, Koa, Happy, Sales), full-stack (e.g., Meteor), desktop (e.g., Electron), and mobile. This proliferation, while offering immense development flexibility, also presents a challenge: how do developers choose a framework, and is security a primary consideration? Dr. Peguero highlighted that developers typically prioritize features, performance, documentation, and community backing, with security often being an afterthought.

This oversight is critical, as security vulnerabilities introduced early in the software development life cycle (SDLC) are more costly to fix later. Advocating for a "shift-left" approach, Dr. Peguero's research posited a central hypothesis: if security mitigations are integrated closer to the framework, developers are less likely to make security mistakes. To test this, she adopted a framework of "levels of mitigation" developed by her colleague, John Steven, and expanded upon it:

  • Level 1: No Mitigation – Vulnerable code exists without any specific protection (e.g., developer-written crypto, Access-Control-Allow-Origin: * in CORS).
  • Level 2: Custom Function – A developer writes their own function for mitigation (e.g., manual input sanitization).
  • Level 3: External Library – A third-party library is used for security (e.g., OWASP ESAPI for sanitization, csurf plugin for Express).
  • Level 4: Built-in Framework Mitigation – Security controls are built into the framework itself (e.g., Spring Security, Angular's context-aware escaping).
  • Level 5: Framework Design Mitigation – Security is inherent in the framework's architecture or protocol design, making certain attacks impossible (e.g., Meteor's WebSocket-based communication preventing CSRF).

These levels provided a structured approach to analyze how different frameworks addressed common vulnerabilities and how effective these approaches were in real-world applications.

Key Findings

▶ Watch: Built-in Angular.js XSS protection proved highly effective. (9:50)

Dr. Peguero's research presented several key findings across different JavaScript application types, offering empirical evidence for her hypothesis and uncovering critical nuances regarding security implementation within frameworks.

Client-Side XSS and Context-Aware Escaping:

The first case study focused on Cross-Site Scripting (XSS) in client-side applications, comparing older template engines like Jade (now Pug) and EJS with AngularJS.

  • Jade and EJS, lacking built-in XSS protection (Level 1), showed high vulnerability rates. Out of 50-60 applications analyzed for each, 25 using Jade and 23 using EJS were found to be vulnerable. Developers rarely implemented custom escaping (Level 2) or used third-party libraries (Level 3).
  • In stark contrast, AngularJS, which featured context-aware escaping built directly into the framework (Level 4), exhibited a very low number of XSS vulnerabilities. The framework automatically escaped user input based on the HTML context, significantly reducing the burden on developers.
  • Finding: Built-in, context-aware mitigations (Level 4) are highly effective in preventing XSS vulnerabilities compared to frameworks that require developers to implement their own protections.

Server-Side CSRF and the Importance of Defaults:

The second study investigated Cross-Site Request Forgery (CSRF) in server-side JavaScript frameworks, including Express, Koa, Happy, Sales, and Meteor.

  • Express, Koa, and Happy did not have built-in CSRF protection but offered plugins (Level 3). However, developers rarely used these plugins.
  • Sales.js had built-in CSRF protection (Level 4), but critically, this protection was disabled by default. Consequently, Sales.js applications showed similar vulnerability rates to Express, despite having a more robust mitigation available.
  • Happy.js applications surprisingly showed the highest level of protection, not due to framework plugins, but because developers chose to implement JSON Web Tokens (JWTs) for authentication. JWTs, sent in HTTP headers rather than cookies, inherently prevent cookie-based CSRF attacks by design (Level 5). This was a developer decision, not a framework default.
  • Meteor, a full-stack framework, demonstrated a unique Level 5 mitigation. Its communication primarily occurs over WebSockets using a custom DDP protocol, rather than solely HTTP. Since cookies are not continuously sent with every request over WebSockets, the fundamental premise of a CSRF attack (hijacking a cookie-laden request) is largely negated.
  • Key Finding: The presence of built-in security (Level 4) is insufficient if it's not enabled by default. Security defaults are paramount. Furthermore, architectural choices like using JWTs or WebSocket protocols (Level 5) can eliminate entire classes of vulnerabilities.

Desktop Electron Applications and Slow Adoption of Secure Defaults:

The final case study focused on Electron, the dominant framework for desktop JavaScript applications. Dr. Peguero analyzed 141 open-source Electron applications using the open-source tool Electronegativity.

  • The analysis revealed a high number of false positives (nearly 1,000 out of 1,200 potential vulnerabilities) due to Electronegativity's simplistic Abstract Syntax Tree (AST) analysis, which lacked full data flow capabilities. Manual triage was essential.
  • Eight top vulnerabilities were identified, with six deemed fixable at the framework level (Level 4). Dr. Peguero highlighted specific examples:
  • Node Integration: By default, Electron allowed web content to access Node.js APIs, giving web pages full access to the client's operating system if malicious code was injected. This dangerous default was finally changed to false in Electron version 5.
  • Context Isolation: This feature separates the JavaScript contexts of the web view and the Node.js backend, preventing prototype pollution attacks where malicious web code could override built-in JavaScript methods (like indexOf) and execute arbitrary code on the server side. This was also false by default and only changed to true in Electron version 12, years after the initial research.
  • Finding: While framework-level improvements (Level 4) are possible and highly effective, their adoption can be extremely slow, often taking many years to implement secure defaults, if at all. This emphasizes the need for developers to actively configure security settings and for tooling to help identify these issues.

Technical Deep Dive

▶ Watch: Framework security defaults are critically important for protection. (17:50)

Dr. Peguero's research provides a granular look at how different JavaScript frameworks handle, or fail to handle, critical security vulnerabilities. The technical deep dive into XSS, CSRF, and Electron-specific issues highlights the mechanisms at play.

Cross-Site Scripting (XSS) and Context-Aware Escaping:

XSS occurs when an attacker injects malicious client-side scripts into web pages viewed by other users. These scripts can bypass access controls, steal cookies, or deface websites.

  • Jade/Pug and EJS: These template engines, popular in earlier client-side development, provided no inherent protection against XSS. Developers were responsible for manually escaping user-supplied input before rendering it. This often involved writing custom functions (Level 2) or integrating external sanitization libraries like OWASP ESAPI (Level 3). The research showed that most developers either overlooked this or implemented it incorrectly, leading to high vulnerability rates. For instance, displaying user-generated rich text without proper sanitization allows <img> tags with onerror attributes or <script> tags to execute.
  • AngularJS: This framework introduced context-aware escaping (Level 4). Instead of a generic escape function, AngularJS understood the rendering context (e.g., HTML attribute, raw text, URL) and applied the appropriate escaping mechanism automatically. For example, if a variable was rendered within an HTML attribute, it would be URL-encoded; if it was within a <div>, it would be HTML-encoded. This intelligent, built-in protection significantly reduced the likelihood of XSS, as developers no longer had to manually decide and apply the correct escaping.

Cross-Site Request Forgery (CSRF) and Protocol Design:

CSRF attacks trick authenticated users into sending unintended requests to a web application. The attack relies on the browser automatically attaching session cookies to requests to the target domain.

  • Common Protections: Traditional CSRF defenses include CSRF tokens (random, unguessable values included in forms and validated on the server, often implemented via Level 3 plugins like csurf for Express) and Same-Site Cookies (a browser-level defense, now widely supported, that restricts when cookies are sent with cross-site requests).
  • Sales.js's Built-in Protection (Level 4): Sales.js offered built-in CSRF protection, typically involving token generation and validation. However, its default setting was false, meaning developers had to explicitly enable it. This highlights that even robust Level 4 mitigations can be ineffective if not securely configured by default.
  • JWT Tokens (Level 5): JSON Web Tokens offer an architectural solution to CSRF. Unlike session cookies, JWTs are typically stored in client-side storage (e.g., localStorage) and sent with each request in an HTTP header (e.g., Authorization: Bearer <token>). Since browsers do not automatically attach JWTs to cross-site requests, the fundamental mechanism of a cookie-based CSRF attack is bypassed. While JWTs have their own security considerations (e.g., XSS can steal them), they effectively eliminate CSRF.
  • Meteor's WebSocket Protocol (Level 5): Meteor, a full-stack framework, uses its own Distributed Data Protocol (DDP), which primarily communicates over WebSockets. While the initial connection might involve an HTTP handshake and cookies, subsequent real-time communication occurs over the WebSocket channel. Once the WebSocket connection is established, persistent cookies are not automatically sent with every message. An attacker's website, even if loaded in the same browser, cannot easily hijack an active WebSocket connection or inject messages without explicit user interaction or a separate vulnerability. This design choice inherently protects Meteor applications from traditional cookie-based CSRF.

Electron Security and Insecure Defaults:

Electron applications, which embed web technologies (Chromium and Node.js) to build desktop apps, face unique security challenges.

  • Node Integration: This setting allows JavaScript code running in a web page (the "web view") to access Node.js APIs, including powerful system-level functions like file system access (fs), process execution (child_process), and network operations. If nodeIntegration was enabled (the default prior to Electron v5) and an attacker could inject malicious JavaScript into the web view (e.g., via XSS), they would gain full control over the user's operating system. The change to nodeIntegration: false by default was a critical Level 4 mitigation.
  • Context Isolation: This feature creates separate JavaScript contexts for the web page and the Electron internal APIs. When contextIsolation was disabled (the default prior to Electron v12), malicious code in the web page could use prototype pollution to inject properties or methods into global JavaScript objects (e.g., Object.prototype). This could then be exploited to override built-in functions (e.g., Array.prototype.indexOf) and execute arbitrary code in the privileged Node.js context. Enabling contextIsolation (Level 4) prevents this type of attack by isolating the potentially malicious web code from the sensitive Node.js environment.
  • Electronegativity: Dr. Peguero used this open-source static analysis tool. While useful for identifying potential issues, its limitations (e.g., no data flow analysis, leading to many false positives like the sandboxing example where a variable sandbox was correctly set to true but not recognized by the tool) necessitated significant manual triage. This underscores the challenges of automated static analysis without sophisticated program understanding.

Demo / Proof of Concept

▶ Watch: Electron's node integration and context isolation defaults. (21:00)

While the talk did not feature a live exploit demonstration, Dr. Peguero did present a tangible outcome of her research in the form of a Visual Studio (VS) plugin for Electron development. This plugin, based on the principles of the Electronegativity tool, serves as a practical proof of concept for integrating early security feedback into the developer workflow.

The VS plugin is designed to be run directly within the Integrated Development Environment (IDE) as developers write code. Its primary function is to highlight potential vulnerabilities, particularly those common in Electron applications that Dr. Peguero identified in her research. For example, it would flag usage of insecure functions or contexts where security-sensitive decisions are being made. The plugin goes beyond mere flagging; it aims to be educational, providing developers with:

  • Contextual information about the potential vulnerability.
  • Suggestions on how to fix the issue, often pointing to secure configurations or alternative API usages.
  • Interactive prompts, such as asking "Are you sure you want to allow HTTP URLs here?" if user-supplied input is being used in a URL context, encouraging developers to consider HTTPS enforcement or input validation.

This open-source plugin represents a Level 3 mitigation, providing developers with immediate feedback and guidance, effectively shifting security left by preventing mistakes before they are committed to the codebase. It acknowledges that while framework-level fixes can be slow, empowering developers with timely, actionable security intelligence is crucial.

Defensive Implications

▶ Watch: Auditors' role in assessing framework security early on. (28:00)

The research presented by Dr. Ksenia Peguero offers critical insights for defenders, developers, and security teams seeking to bolster the security of JavaScript applications:

  1. Prioritize Security in Framework Selection: Before adopting any new JavaScript framework, security teams should conduct a thorough assessment. This involves reviewing the framework's explicit security documentation, examining its default security configurations, evaluating its track record for addressing security vulnerabilities (bug fixes, disclosure policies), and assessing the activity and responsiveness of its maintainers. Frameworks with strong, opinionated security features and transparent security practices should be preferred.
  2. Scrutinize Default Configurations: The most significant finding from the CSRF study was that built-in security features (Level 4) are ineffective if disabled by default. Defenders must ensure that developers are aware of and actively configure security-critical settings. This might involve creating secure baseline configurations, using automated checks, or providing clear guidelines for enabling essential protections like CSRF tokens, nodeIntegration: false, and contextIsolation: true.
  3. Embrace Architectural Security (Level 5): Whenever possible, choose frameworks or architectural patterns that inherently mitigate entire classes of vulnerabilities. The examples of Meteor's WebSocket protocol for CSRF and the use of JWT tokens illustrate how fundamental design choices can eliminate attack vectors. Security architects should consider these options during the design phase.
  4. Leverage Built-in Framework Protections (Level 4): Prefer frameworks that offer robust, context-aware, and automatically applied security features (like AngularJS's XSS protection). These are generally more effective and less prone to developer error than relying on external libraries or custom code.
  5. Integrate Static Analysis Tools Early: Tools like the Electron VS plugin, or more sophisticated SAST (Static Application Security Testing) solutions, can identify potential vulnerabilities during development. Even if framework fixes are slow to materialize, these tools provide immediate feedback, helping developers correct insecure coding practices before they become ingrained.
  6. Stay Updated and Patch Regularly: Frameworks evolve, and security improvements are often introduced in newer versions (e.g., Electron's changes to nodeIntegration and contextIsolation). Keeping frameworks and their dependencies updated is crucial to benefit from these advancements.
  7. Educate Developers on Framework Security: Developers need to understand not just how to use a framework, but also its security implications. Training should cover common vulnerabilities, how the chosen framework addresses them, and the importance of secure defaults and configurations.
  8. Consider Type-Safe Languages: As noted in the Q&A, using TypeScript can eliminate certain types of vulnerabilities by enforcing type checks, preventing issues like feeding a string where a number is expected. While not a panacea for all security problems, it adds a valuable layer of defense.

Key Takeaways

  • Frameworks are a primary determinant of application security: The choice and configuration of JavaScript frameworks profoundly impact the prevalence of vulnerabilities like XSS and CSRF.
  • Built-in security is superior: Features built directly into frameworks (Level 4) are significantly more effective at preventing vulnerabilities than relying on external libraries (Level 3) or custom developer code (Level 2).
  • Secure defaults are non-negotiable: Even robust built-in security features are ineffective if they are disabled by default. Frameworks must prioritize secure-by-default configurations, and developers must actively verify and enable them.
  • Architectural design can eliminate entire attack classes: Fundamental design choices, such as using WebSocket protocols or JWT tokens (Level 5), can inherently mitigate vulnerabilities like CSRF by altering the underlying communication mechanisms.
  • Framework-level improvements can be slow: While frameworks eventually adopt secure defaults (e.g., Electron's nodeIntegration and contextIsolation), these changes can take many years, leaving applications vulnerable in the interim.
  • Shift-left with developer tooling: IDE plugins and static analysis tools are crucial for providing early, actionable security feedback to developers, helping them prevent common mistakes even when framework-level fixes are lagging.

About the Speaker(s)

Dr. Ksenia Peguero is a Senior Manager of Research Engineering at Synopsis Software Integrity Group. In her role, she leads a team focused on conducting in-depth research that directly informs and enhances Synopsys's suite of software security products, including static (SAST) and dynamic (DAST) analysis tools. Her day-to-day work involves analyzing vast amounts of code, frameworks, libraries, and technologies to identify common developer mistakes and potential security vulnerabilities. Dr. Peguero recently completed her PhD, with the research presented in this talk forming the core of her doctoral work. She expressed her happiness at being able to present her findings at an in-person conference after a long hiatus.

Reviews

Dr. Zero (Offensive Security Researcher) — SOLID

A competent, data-driven academic look at how framework defaults shape application security. The empirical work is sound, but analyzing AngularJS and Jade makes this feel like a time capsule from 2016.

Heather Calloway (CISO) — STRONG ACCEPT

Peguero's data proves what AppSec teams have suspected for years: developer training doesn't scale, but secure framework defaults do. This is a mandatory watch for your enterprise architecture board before they approve the next JavaScript framework for production.

→ Top-rated talks at Swiss Cyber Storm 2021

All talks from Swiss Cyber Storm 2021