Protection method, equipment and medium
By configuring security policies for components of the front-end application and instantiating runtime sandboxes, the problems of coarse-grained protection and dynamic content injection in existing technologies are solved, achieving fine-grained control and real-time protection at the component level, thereby improving the security and performance of the front-end application.
Patent Information
- Application Number
- CN202511552129.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-28
- Publication Date
- 2026-02-10
AI Technical Summary
Existing protection measures are coarse-grained and cannot provide fine-grained control at the front-end component level, resulting in a "one-size-fits-all" protection strategy that affects legitimate functions or creates blind spots in protection. They are unable to cope with dynamic content injection of malicious scripts and lack of isolation between component communication in modern front-end applications, cannot effectively resist fileless attacks and CSRF attacks, have complex token management, lack real-time monitoring and response mechanisms, cannot effectively resist the risks of third-party libraries, and are disconnected from development and security.
By configuring security policies for components of the front-end application and instantiating runtime sandboxes, component-level environment isolation is achieved. The sandbox manager and security proxy layer are used to monitor and intercept component behavior in real time. Sandbox IDs and CSRF tokens are used for fine-grained control, enabling controlled communication between components.
It improves the accuracy and flexibility of security protection, enabling immediate interception and handling of malicious behavior, reducing development costs, enhancing the robustness and fault tolerance of applications, preventing lateral attacks, simplifying the CSRF protection process, and improving runtime protection capabilities.
Smart Images

Figure CN121508920A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of network security, and in particular to a protection method, device and medium. BACKGROUND
[0002] Existing protection measures have coarse granularity. For example, traditional Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) protection are mostly global or server-side, such as global input sanitization, firewall rules or server-generated CSRF tokens. These methods cannot perform fine-grained control at the front-end component level, resulting in a "one-size-fits-all" protection strategy that may affect legitimate functions or have blind spots in protection.
[0003] Moreover, modern front-end applications use JavaScript to dynamically generate and modify DOM content, and traditional Content Security Policy (CSP) and sanitization methods are difficult to cope with complex runtime behaviors, resulting in attackers injecting malicious scripts using dynamic content. SUMMARY
[0004] Embodiments of the present application provide a protection method, device and medium to solve the technical problem of how to implement fine-grained component-level protection and improve runtime protection capabilities.
[0005] In a first aspect, embodiments of the present application provide a protection method, the method comprising: in response to loading a front-end application, performing security preprocessing on at least one component, wherein the component is a component to be rendered corresponding to the front-end application, and the security preprocessing is used to configure a security policy corresponding to the component for the component; and in response to rendering of at least one of the components, instantiating a runtime sandbox for each of the components to achieve environmental isolation of the components.
[0006] In a second aspect, embodiments of the present application also provide a protection device, the device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the protection method of the first aspect described above.
[0007] In a third aspect, embodiments of the present application also provide a computer storage medium storing computer executable instructions, and the computer executable instructions, when executed, implement the protection method of the first aspect described above.
[0008] The protection method, device and medium provided by the embodiment of the application have the following beneficial effects. In the embodiment of the application, the components to be rendered can be preprocessed for security, and different security policies are configured for them. In this way, the security protection is sunk from the traditional global or server side to the component level of the front end. This fine-grained control avoids the drawbacks of "one-size-fits-all" and improves the accuracy and flexibility of security protection. Moreover, a corresponding runtime sandbox can be created for the components, which can immediately intercept and process malicious behavior, and can improve the runtime protection capability. BRIEF DESCRIPTION OF DRAWINGS
[0009] The accompanying drawings described herein are used to provide further understanding of the application, and form a part of the application. The illustrative embodiments of the application and their descriptions are used to explain the application, and do not constitute an improper limitation on the application. In the drawings: Figure 1 A protection method flowchart is provided for the embodiment of the application. Figure 2 An internal structure schematic diagram of a protection device is provided for the embodiment of the application. DETAILED DESCRIPTION
[0010] To make the purpose, technical solutions and advantages of the application clearer, the technical solutions of the application will be described clearly and completely below in combination with the specific embodiments of the application and the corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the application, not all the embodiments. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the application.
[0011] The existing protection method has the following problems: (1) The granularity of the existing protection measures is coarse. Traditional XSS and CSRF protection is mostly global or server-side, such as global input purification, firewall rules or server-generated CSRF tokens. These methods cannot control the granularity at the front-end component level, resulting in a "one-size-fits-all" protection strategy that may affect legitimate functions or have a blind spot in protection.
[0012] (2) Security risks of dynamically generated content. Modern front-end applications use a lot of JavaScript to dynamically generate and modify DOM content. Traditional content security policies and sanitization methods are difficult to cope with complex runtime behaviors, resulting in attackers injecting malicious scripts using dynamic content.
[0013] (3) Lack of isolation between components. In complex Single Page Applications (SPA), components often have access to each other or share global variables, which provides an opportunity for lateral movement for malicious components or hijacked components. Once a component is compromised, the entire application can be affected.
[0014] (4) Difficulty in defending against fileless attacks. Some advanced XSS attacks do not rely on <script>标签,而是通过动态调用函数、修改原型链等方式执行恶意代码,传统的基于标签或字符串过滤的防护方法对此无能为力。
[0015] (5)CSRF令牌管理复杂,传统的CSRF防护依赖于服务器生成和前端存储的令牌,这增加了前端状态管理的复杂度。攻击者仍有可能通过一些手段窃取或绕过令牌,且对于跨域请求的处理也较为复杂。
[0016] (6)开发与安全脱节,前端开发人员通常更关注业务功能和用户体验,而安全防护被视为一个独立的、需要专业人员处理的额外工作。这导致安全措施往往在项目后期才被加入,增加了开发成本和维护难度。
[0017] (7)无法有效抵御第三方库的风险,现代前端项目严重依赖于NPM等生态中的第三方库。如果某个第三方库存在漏洞或恶意代码,传统的防护手段难以对其进行隔离,从而将风险引入整个应用。
[0018] (8)缺乏实时监控与响应机制,现有的前端安全方案大多是被动式的,无法在恶意行为发生时立即进行运行时监控和隔离。
[0019] 为了解决上述至少之一的问题,本申请实施例提供了一种防护方案,下面通过附图对本申请实施例提出的技术方案进行详细的说明。
[0020] 图1为本申请实施例提供的一种防护方法的流程图。如图1所示,本申请实施例提供的一种防护方法,具体包括以下步骤:步骤101、响应于加载前端应用,对至少一个组件进行安全预处理。
[0021] 其中,所述组件为所述前端应用对应的待渲染的组件,所述安全预处理用于为所述组件配置与所述组件对应的安全策略。
[0022] 在实际应用中,本申请提供的防护方法可以由沙箱管理器执行。
[0023] 在前端开发中,前端应用(Frontend Application)是用户直接交互的完整软件系统,通常运行在浏览器或移动端,包含界面、逻辑、状态管理等。例如,一个电商网站、一个管理后台等。组件(Component)是前端应用中可复用、独立的UI单元,封装了特定的功能、样式和逻辑。前端应用由多个组件构成,组件是应用的"构建块”。
[0024] 在本申请实施例中,在前端应用启动时,沙箱管理器可以扫描至少一个待渲染的需要保护的组件,例如登录表单组件(LoginFormComponent)或评论区组件(CommentSection)。其中,LoginFormComponent可以用于提供用户登录界面,收集用户名、密码等凭证,并验证身份;CommentSection可以用于允许用户对内容(如文章、视频)发表评论、回复,促进互动。
[0025] 在本申请实施例中,可以对待渲染的组件进行安全预处理,为上述组件配置与该组件对应的安全策略,这样将安全防护从传统的全局或服务器端下沉到前端的组件级别,这种细粒度的控制可以避免"一刀切”的弊端,提高安全防护的精准性和灵活性。而且,可以为不同的组件配置定制化的安全策略。例如,处理用户输入的评论区组件可能被禁止访问任何全局变量,而只用于展示的组件则可以有更宽松的权限。通过上述策略,可以实现安全防护的精细化管理。
[0026] 步骤102、响应于至少一个所述组件进行渲染,为每个所述组件实例化一个运行时沙箱,以实现对所述组件的环境隔离。
[0027] 在实际应用中,沙箱 (Sandbox)是一种隔离环境,用于限制程序或代码的执行权限,防止其对外部系统造成影响。它可以将可疑文件或程序隔离在沙箱内部,并诱导其在沙箱环境中运行,通过监控程序行为(如自我复制、覆盖文件等)来识别高风险动作。运行时沙箱 (Runtime Sandbox)是在代码执行时动态创建和生效的沙箱,而非静态分析或全局配置。
[0028] 在本申请实施例中,在组件被渲染时,可以为组件实例化一个运行时沙箱,这样,组件的所有代码将在该沙箱内执行,而不是在全局的环境中。例如,可以在浏览器内存中为该组件实例化一个轻量级的运行时沙箱。该运行时沙箱充当了组件代码与浏览器主线程之间的中间层。所有在该组件内执行的脚本、动态生成的HTML内容以及发出的异步请求,都必须通过这个运行时沙箱。在实际应用中,可以通过 Proxy 对象、iframe 或者其他任何技术手段实现运行时沙箱,以实现为组件创建隔离环境,具体运行时沙箱的实现机制,本申请不作具体限定。
[0029] 如此,能够在恶意行为发生时(即代码执行时)立即进行拦截和处理,可以提升运行时防御能力。而且通过创建运行时沙箱,无论是动态生成的恶意脚本,还是试图访问敏感信息的代码,都将在沙箱内部被即时检测和阻止。这大大提升了对无文件攻击和新型攻击手法的防御能力,实现了从被动防御到主动防御的转变。
[0030] 这样,能够在应用运行时为每个前端组件动态地创建一个独立的沙箱环境。与传统的静态安全分析或全局配置不同,可以实现在代码执行层面的微观隔离。通过在组件级别实现运行时隔离,将安全防护的责任从全局下沉到最小可操作单元,显著提高前端应用的安全性。它不仅能有效抵御已知的XSS和CSRF攻击,还能够对未知或新型的攻击手法提供更强的鲁棒性,因为它限制了攻击代码的执行环境和影响范围,从而确保前端界面的完整性和用户数据的安全。
[0031] 通过本申请提供的方法,将安全防护内嵌到组件层,可以使得安全不再是开发后期才需考虑的额外工作。沙箱机制可以自动处理大部分安全问题,开发人员只需专注于业务逻辑,无需手动添加复杂的输入净化或CSRF令牌管理代码。这不仅降低了开发成本,还从根本上减少了人为疏忽导致的安全漏洞,将安全责任从开发人员转移到了系统本身。而且,现代前端项目大量依赖第三方库。本申请所提出的沙箱机制,能够将不确定或来自外部的库代码隔离在沙箱中运行。即使某个第三方库被植入恶意代码,该恶意代码也无法逃脱沙箱的限制,无法影响到主应用或其他组件,从而有效防止供应链攻击,可以隔离第三方库带来的风险。
[0032] 在实际应用中,可以采用"最小权限”原则,每个组件只拥有完成自身功能所需的最小权限。即使攻击者成功攻破了某个组件,其影响范围也被严格限制在该组件的沙箱内,无法向外传播。这种隔离机制极大地增强了应用的健壮性和容错能力,防止了"一点突破,全盘皆输”的局面。而且,由于大部分安全检查都在前端完成,能够在请求发送到服务器之前就阻止恶意行为。这意味着服务器可以更快地响应合法请求,减少了无效请求对服务器资源的消耗,从而间接提升了应用的整体性能和用户体验。
[0033] 在本申请实施例中,可以对待渲染的组件进行安全预处理,为其配置不同的安全策略,这样,将安全防护从传统的全局或服务器端下沉到前端的组件级别,这种细粒度的控制避免了"一刀切”的弊端,提高了安全防护的精准性和灵活性。而且,可以为组件创建对应的运行时沙箱,能够在恶意行为发生时立即进行拦截和处理,可以提升运行时防御能力。
[0034] 在一个可选的实现方式中,所述响应于加载前端应用,对至少一个组件进行安全预处理,可以包括以下步骤:步骤1011、响应于加载前端应用,基于至少一个组件的类型、来源及依赖关系,为至少一个所述组件生成对应的沙箱ID;步骤1012、基于所述组件的风险等级和功能需求,为所述组件配置相应的安全策略。
[0035] 在上述实施例中,在前端应用启动时,可以为至少一个组件,进行安全预处理,如此,可以生成一个沙箱ID和一套严格的安全策略。其中,可以根据组件的类型、来源和依赖关系,为其生成一个唯一的沙箱ID。该沙箱ID可以为每个组件分配独立标识,确保资源(如内存、文件、网络端口)不会因命名冲突或路径重叠而互相干扰。而且,沙箱ID可关联组件的创建、销毁和状态,便于动态加载或卸载时追踪资源释放情况。在实际应用中,也可以通过其他方式确定沙箱ID,具体不作限制。
[0036] 在上述实施例中,可以根据每个组件的风险等级和功能需求,为其配置不同的安全策略。例如,处理用户输入的评论区组件可以配置最严格的沙箱规则,可能被禁止访问任何全局变量,而只显示静态内容的组件则可以相对宽松。在实际应用中,也可以基于其他条件,配置安全策略,具体不作限制。这样,可以提高安全防护的精准性和灵活性。
[0037] 在一个可选的实现方式中,所述安全策略可以包括以下至少之一:(1)限制所述组件对外部全局变量的直接访问;(2)对所述组件内部生成的文档对象模型DOM 元素进行内容安全策略限制;(3)对所述组件发起的网络请求进行身份验证与过滤。
[0038] 在上述实施例中,安全策略可以为限制组件对外部全局变量(例如 window、document)的直接访问,也可以是对组件内部生成的文档对象模型(Document ObjectModel,DOM)元素进行内容安全策略限制,还可以对组件发起的网络请求进行身份验证与过滤。其中,DOM是将网页文档(如 HTML 或 XML)表示为树状结构的编程接口,允许程序(如JavaScript)动态访问和修改文档的内容、结构和样式。安全策略可以基于组件的风险等级和功能需求等进行确定,不作具体限制。不同的安全策略可以实现不同的防护目标。
[0039] 在一个可选的实现方式中,所述响应于至少一个所述组件进行渲染,为所述组件实例化一个运行时沙箱,包括:响应于至少一个所述组件进行更新,为所述组件实例化一个运行时沙箱;或,响应于至少一个所述组件进行渲染,为所述组件实例化一个运行时沙箱。
[0040] 在实际应用中,前端应用启动后,组件可以先更新数据然后进行渲染,此时,可以在组件更新时,为该组件实例化一个运行时沙箱,也可以在组件渲染时,为该组件实例化一个运行时沙箱,具体的时间点,不作限制。需要说明的是,仅可以为每个组件创建一个运行时沙箱,不可以重复创建。
[0041] 在一个可选的实现方式中,所述为所述组件实例化一个运行时沙箱,包括:基于所述安全策略,使用安全代理,为所述组件实例化一个运行时沙箱,其中,所述运行时沙箱用于阻止跨站脚本攻击,所述安全代理包括DOM代理;和 / 或,基于所述安全策略,使用安全代理,为所述组件实例化一个运行时沙箱,其中,所述运行时沙箱用于防御跨站请求伪造,所述安全代理包括网络请求代理。
[0042] 在实际应用中,代理 (Proxy)是一种设计模式,用于在目标对象(如浏览器API)和调用者之间建立一个中间层,以拦截、审查和修改操作。在上述实施例中,针对不同的安全策略,可以使用不同的安全代理来创建运行时沙箱,从而实现不同的防御目标。
[0043] 在实际应用中,在安全策略包括限制组件对外部全局变量的直接访问的情况下,以JavaScript Proxy为例,在组件代码执行前,沙箱管理器可以创建一个Proxy对象来代理window和document等全局对象。例如,当组件尝试访问window.location.href时,代理的get陷阱(trap)可以被触发。运行时沙箱可以检查该操作是否合法,若不合法则返回一个空值或抛出错误,从而防止恶意脚本获取敏感信息或进行页面跳转。
[0044] 在实际应用中,在安全策略包括对组件内部生成的文档对象模型DOM 元素进行内容安全策略限制,,例如DOM操作拦截的情况下,可以利用JavaScript的Proxy对象,构成沙箱,具体的,可以采用DOM代理对组件的操作进行拦截,这样可以进行XSS防御。在实际应用中,在安全策略包括对组件发起的网络请求进行身份验证与过滤的情况下,可以使用网络请求代理,对网络请求进行审核。这样,可以进行CSRF防御。
[0045] 在一个可选的实现方式中,所述运行时沙箱用于阻止跨站脚本攻击,包括:响应于所述组件将未知内容插入DOM,所述运行时沙箱使用所述DOM代理拦截所述组件的插入操作,其中,所述DOM代理对所述未知内容进行净化,以移除恶意脚本。
[0046] 在实际应用中,Document对象是浏览器中表示整个网页文档的核心接口,属于WebAPI的一部分。它是 DOM的根节点,提供了访问和操作网页内容(如 HTML、CSS、图片等)的入口。对于document对象,可以拦截createElement, appendChild,innerHTML等关键方法。其中,createElement、appendChild和innerHTML是 JavaScript 中操作 DOM的三种核心方法,createElement用于创建一个新的 DOM 元素节点(如、),但不会将其插入到文档中;appendChild可以将已存在的节点插入到父节点的子节点列表末尾;innerHTML可以直接设置或获取元素的 HTML 内容(包括子节点)。
[0047] 在上述实施例中,当用户在评论区组件中输入未知内容,例如包括<script>alert(1)< / script> When the comment component is inserted into the DOM, it can use innerHTML to insert its content. This operation can be intercepted by the DOM proxy of the runtime sandbox, which can perform sanitization on the unknown content to remove malicious scripts, so that only the alert(1) text is inserted, not executable code. During the sanitization process, all suspicious HTML tags (such as <script>、<iframe)和事件处理属性(如onclick、onload),只保留安全的HTML内容,然后才允许其插入DOM。
[0048] 在一个可选的实现方式中,所述运行时沙箱用于防御跨站请求伪造,包括:响应于所述沙箱发起网络请求,所述运行时沙箱使用所述网络请求代理拦截所述网络请求,并在所述网络请求的请求头中加入一个与所述沙箱ID绑定的CSRF令牌,其中,所述网络请求对应的服务器基于所述CSRF令牌,确定是否接受所述网络请求。
[0049] 在实际应用中,Fetch对象是浏览器提供的用于Web数据交互的JavaScript原生API,它通过抽象HTTP接口实现高效通信,核心包括Request、Response、Headers等对象,支持基于Promise的异步请求,是XMLHttpRequest的现代替代方案。XMLHttpRequest(简称XHR)是浏览器内置的 JavaScript 对象,用于在后台与服务器异步交换数据,无需重新加载整个页面。它是实现 AJAX(Asynchronous JavaScript and XML)技术的核心工具,允许网页动态更新内容、提交表单或获取服务器数据,从而提升用户体验。对于fetch或XMLHttpRequest对象,安全代理可以拦截所有发出的请求。在拦截时,可以为请求头强制添加一个唯一的、由沙箱管理器生成的随机令牌(Token)。在服务器端,可以通过验证这个令牌来确认请求的合法性,从而有效防御CSRF攻击。同时,安全代理还可以限制组件只能向特定的白名单域名发送请求。
[0050] 在上述实施例中,当用户点击一个表单提交按钮时,组件内部的fetch请求可以被运行时沙箱的网络请求代理拦截。该网络请求代理可以自动在网络请求的请求头中加入一个与该沙箱ID绑定的CSRF令牌。服务器收到请求后,可以验证这个令牌是否有效且与发起请求的源匹配。如果请求来自外部恶意网站,因为没有正确的令牌,该请求将被服务器拒绝。这样,在网络请求中自动注入一个与沙箱实例绑定的随机令牌。这简化了CSRF防护流程,并将令牌管理从开发人员手中转移到了系统层面,可以防御CSRF攻击。
[0051] 在实际应用中,通过对关键的浏览器API(如 fetch、XMLHttpRequest、innerHTML、document.cookie等)进行代理和重写,可以实现对组件行为的实时监控和拦截。所有从组件沙箱发出的操作都必须经过安全代理的审查和过滤。不仅可以有效阻止XSS攻击,还可以防御CSRF攻击。
[0052] 在一个可选的实现方式中,在所述响应于至少一个所述组件进行渲染,为所述组件实例化一个运行时沙箱之后,所述方法还包括:响应于所述组件与目标模块基于预设接口进行通信,监测所述组件与所述目标模块的通信过程,以确保所述通信过程的安全性。
[0053] 本申请提供了一种安全的组件间通信机制。该机制允许沙箱化的组件之间通过预设接口进行数据交换,而不是直接共享内存或访问彼此的DOM。在上述实施例中,预设接口可以为预定义的、受限的接口,同时,在组件与目标模块基于预设接口进行通信的情况下,沙箱管理器可以监测组件与目标模块的通信过程,以确保通信过程的安全性。这确保了即使组件被沙箱隔离,它们仍能以一种受控的方式进行合法交互,同时防止恶意组件影响其他部分。这种受控的通信方式进一步降低了恶意组件影响其他组件的风险,形成了多重防护。
[0054] 在一个可选的实现方式中,所述目标模块包括所述组件之外的另一组件;所述预设接口包括事件总线或消息队列;所述组件与目标模块基于预设接口进行通信,包括:在所述组件请求调用所述另一组件的方法的情况下,所述组件通过事件总线或消息队列向所述另一组件发送消息。
[0055] 在实际应用中,目标模块可以为组件之外的另一组件,也可以为外部系统,具体不做限制。当组件需要与另一组件进行通信时,例如,组件需要调用另一组件的方法时,不能直接调用,可以通过事件总线或消息队列向另一组件发送受限的消息,同时,沙箱管理器可以监听这些消息,并确保其内容以及目标都是安全的。
[0056] 以上为本申请提出的方法实施例。基于同样的发明构思,本申请实施例还提供了一种防护设备,其结构如图2所示。
[0057] 图2为本申请实施例提供的一种设备内部结构示意图。如图2所示,设备包括:至少一个处理器201;以及,与至少一个处理器通信连接的存储器202;其中,存储器202存储有可被至少一个处理器执行的指令,指令被至少一个处理器201执行,以使至少一个处理器201能够:执行上述所述的防护方法。
[0058] 在实际应用中,本申请实施例还可以提供一种防护系统,该防护系统可以包括沙箱管理器、安全代理层以及组件隔离器。其中,沙箱管理器是整个系统的核心大脑。它负责在应用启动时加载和初始化所有需要沙箱化的组件。沙箱管理器可以根据预设的配置或运行时分析,为每个组件生成独立的沙箱实例,并管理这些实例的生命周期、资源分配和安全策略。安全代理层(Security Proxy Layer)是沙箱内部的核心安全机制。所有从沙箱内部发出的网络请求(如Fetch, XMLHttpRequest)、DOM操作(如innerHTML, createElement)和全局变量访问都可以被这个代理层拦截和审查。代理层可以根据沙箱管理器的安全策略,决定是放行、修改请求还是直接阻止。组件隔离器(Component Isolator)是一个轻量级的运行时环境,用于承载被沙箱化的组件代码。它可以是浏览器原生的<iframe>,也可以是利用JavaScript的Proxy或with语法糖实现的隔离环境。隔离器可以确保组件代码无法直接访问外部环境,只能通过安全代理层与外界交互。
[0059] 本申请的一些实施例提供的对应于图1的一种的非易失性计算机存储介质,存储有计算机可执行指令,计算机可执行指令设置为:执行上述所述的防护方法。
[0060] 本申请中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于物联网设备和介质实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
[0061] 本申请实施例提供的系统和介质与方法是一一对应的,因此,系统和介质也具有与其对应的方法类似的有益技术效果,由于上面已经对方法的有益技术效果进行了详细说明,因此,这里不再赘述系统和介质的有益技术效果。
[0062] 本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
[0063] 本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
[0064] 这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
[0065] 这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
[0066] 在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入 / 输出接口、网络接口和内存。
[0067] 内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和 / 或非易失性内存等形式,如只读存储器(ROM)或闪存(flashRAM)。内存是计算机可读介质的示例。
[0068] 计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitorymedia),如调制的数据信号和载波。
[0069] 还需要说明的是,术语"包括”、"包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句"包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。
[0070] 以上所述仅为本申请的实施例而已,并不用于限制本申请。对于本领域技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本申请的权利要求范围之内。< / script>
Claims
1. A protection method, characterized in that, include: In response to loading a front-end application, security preprocessing is performed on at least one component, wherein the component is a component to be rendered corresponding to the front-end application, and the security preprocessing is used to configure a security policy corresponding to the component. In response to rendering of at least one of the components, a runtime sandbox is instantiated for each of the components to achieve environmental isolation of the components.
2. The method according to claim 1, characterized in that, The security preprocessing of at least one component in response to loading the front-end application includes: In response to loading the front-end application, a corresponding sandbox ID is generated for at least one of the components based on the type, source, and dependencies of at least one component; Based on the risk level and functional requirements of the components, configure corresponding security policies for the components.
3. The method according to claim 2, characterized in that, The security strategy includes at least one of the following: Restrict the component's direct access to external global variables; Content security policies are applied to restrict the Document Object Model (DOM) elements generated internally by the component. The network requests initiated by the component are authenticated and filtered.
4. The method according to claim 1, characterized in that, The response to rendering of at least one of the components, instantiating a runtime sandbox for the component, includes: In response to an update of at least one of the components, instantiate a runtime sandbox for the component; or, In response to rendering of at least one of the components, a runtime sandbox is instantiated for the component.
5. The method according to claim 3, characterized in that, Instantiating a runtime sandbox for the component includes: Based on the security policy, a runtime sandbox is instantiated for the component using a security proxy, wherein the runtime sandbox is used to prevent cross-site scripting attacks, and the security proxy includes a DOM proxy; and / or, Based on the security policy, a runtime sandbox is instantiated for the component using a security proxy, wherein the runtime sandbox is used to defend against cross-site request forgery, and the security proxy includes a network request proxy.
6. The method according to claim 5, characterized in that, The runtime sandbox is used to prevent cross-site scripting attacks, including: In response to the component inserting unknown content into the DOM, the runtime sandbox uses a DOM proxy to intercept the component's insertion operation, wherein the DOM proxy cleanses the unknown content to remove malicious scripts; The runtime sandbox is used to defend against cross-site request forgery, including: In response to the sandbox initiating a network request, the runtime sandbox uses a network request proxy to intercept the network request and adds a CSRF token bound to the sandbox ID to the request header of the network request. The server corresponding to the network request determines whether to accept the network request based on the CSRF token.
7. The method according to claim 1, characterized in that, After instantiating a runtime sandbox for at least one of the components in response to rendering, the method further includes: In response to the communication between the component and the target module based on a preset interface, the communication process between the component and the target module is monitored to ensure the security of the communication process.
8. The method according to claim 7, characterized in that, The target module includes another component besides the aforementioned component; The preset interface includes an event bus or a message queue; The component communicates with the target module based on a preset interface, including: when the component requests to call a method of the other component, the component sends a message to the other component through an event bus or message queue.
9. A protective device, characterized in that, The device includes: At least one processor; And, a memory communicatively connected to the at least one processor; The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform a protection method as described in any one of claims 1 to 8.
10. A computer storage medium storing computer-executable instructions, characterized in that, When the computer-executable instructions are executed, a protection method as described in any one of claims 1 to 8 is implemented.