A Layered Security Framework and Metrics for Analysing Cross-site Scripting Attacks
Abstract
Single Page Applications (SPAs) have become a dominant architecture for modern client-side web systems by shifting state management, routing, and user interface processing to the browser. Although frameworks such as Angular provide built-in security mechanisms, including contextual escaping, template sanitization, and secure data binding, developers may introduce security weaknesses through practices such as unsafe DOM manipulation, dynamic script loading, and improper use of bypass mechanisms. Existing approaches to SPA security assessment primarily focus on identifying known vulnerability patterns through static analysis, providing limited insight into architectural security weaknesses and accumulated security complexity. This study contributes a Metrics-Driven Layered Security Framework (LSF) for assessing and improving the security architecture of Angular SPAs against Cross-Site Scripting (XSS) attacks. The proposed framework organizes SPA security controls into three architectural layers: the Rendering Layer, Control Logic Layer, and Outer Shell Layer. It introduces seven security metrics, including Sanitization Bypass Density, Unmanaged Active Sink Frequency, Maximum Nesting Depth, Cyclomatic Branching Factor, CSP Policy Strictness Score, Boundary Validation Density, and Dependency Vulnerability Coefficient, which are combined into composite layer risk scores for comprehensive security assessment. The framework was empirically evaluated through controlled experiments involving Angular developers, comparing developers using the LSF-supported Layered Security Metrics Tool (LSMT) against developers performing unaided manual security reviews. The findings demonstrated that the proposed metrics and framework improve developers’ ability to identify structurally complex XSS-related weaknesses across Angular SPA security layers. The results demonstrate that the LSF provides a measurable approach for proactive vulnerability identification, architectural security auditing, and integration into Continuous Integration/Continuous Deployment (CI/CD) security processes.