CN-122027293-A - Network resource request interception method and device, electronic equipment and medium
Abstract
The application discloses a network resource request interception method, a device, electronic equipment and a medium, which are applied to a network resource interception system, wherein the network resource interception system and a browser are in communication connection through a full duplex communication channel, and the method comprises the following steps: receiving a resource identifier to be intercepted input by a user, carrying out self-adaptive encapsulation processing on the resource identifier to be intercepted to obtain a target interception list, constructing an interception list update instruction containing the target interception list according to the target interception list, acquiring a network control function state of a browser, and if the network control function state indicates that a network control function of the browser is started, sending the interception list update instruction to the browser through a full duplex communication channel, wherein the browser is used for intercepting a network resource request according to the target interception list. According to the application, the target interception list can be dynamically modified during the operation of the browser, the interception of the network resource request can be realized without additional deployment, and the complexity of intercepting the network resource request is reduced.
Inventors
- CHEN YANGNAN
- Tu Hengqiang
- JI WEI
Assignees
- 赛力斯汽车有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260213
Claims (10)
- 1. The method is characterized by being applied to a network resource interception system, wherein the network resource interception system and a browser are in communication connection through a full duplex communication channel, and the method comprises the following steps: receiving a resource identifier to be intercepted input by a user; Performing self-adaptive encapsulation processing on the resource identifier to be intercepted to obtain a target interception list; Constructing an interception list updating instruction containing the target interception list according to the target interception list; Acquiring a network control function state of the browser; And if the network control function state indicates that the network control function of the browser is started, the interception list updating instruction is sent to the browser through the full duplex communication channel, and the browser is used for intercepting the network resource request according to the target interception list.
- 2. The method of claim 1, wherein the step of adaptively encapsulating the resource identifier to be intercepted to obtain a target interception list includes: The method comprises the steps of obtaining an identification type of a resource identification to be intercepted, wherein the identification type comprises one of a null value, a character string, a list, a tuple and other types, and the other types are other identification types except the null value, the character string, the list and the tuple; If the identification type is the null value, packaging the resource identification to be intercepted as a null list, and taking the null list as a target interception list; If the identification type is the character string, the resource identification to be intercepted is packaged into a unit pixel list, and the unit pixel list is used as a target interception list; if the identification type is the list or the tuple, the resource identification to be intercepted is used as a target interception list; and if the identification type is the other type, generating type error prompt information according to the identification of the resource to be intercepted, and sending the type error prompt information to the user.
- 3. The method of claim 1, wherein the step of constructing an intercept list update instruction comprising the target intercept list from the target intercept list comprises: Performing de-duplication, sequencing and security verification on a plurality of to-be-intercepted resource identifiers in the target interception list to obtain a processed target interception list; if the number of the resource identifiers to be intercepted is greater than a preset number threshold in the processed target interception list, splitting the target interception list into a plurality of target interception sub-lists, and respectively constructing an interception list updating instruction according to the plurality of target interception sub-lists; If the number of the resource identifiers to be intercepted is smaller than or equal to the number threshold value in the target interception list, constructing an interception list updating instruction containing the target interception list according to the target interception list.
- 4. The method according to claim 1, wherein the method further comprises: If the initial state of the network control function indicates that the network control function of the browser is closed, generating a network control domain starting instruction; And sending the network control domain enabling instruction to the browser, wherein the browser is used for starting a network control function according to the network control domain enabling instruction.
- 5. The method of claim 4, wherein after sending the network control domain enable instruction, the method further comprises: if the interception list updating instruction fails to be sent, a network control domain closing instruction is generated; And sending the network control domain closing instruction to the browser, wherein the browser is used for closing a network control function according to the network control domain closing instruction.
- 6. The method of claim 1, wherein after sending the intercept list update instruction to the browser, the method further comprises: Generating an interception list update event, and storing the target interception list and the interception list update event in an associated mode.
- 7. The method according to claim 1, wherein the method further comprises: Receiving a request blocking event sent by the browser, wherein the request blocking event is generated by the browser when a network resource request matched with the target interception list is successfully intercepted; and generating and recording a network resource blocking log according to the received request blocking event.
- 8. A network resource request intercepting device, which is applied to a network resource intercepting system, wherein the network resource intercepting system is in communication connection with a browser through a full duplex communication channel, and the device comprises: the identification acquisition module is used for receiving the resource identification to be intercepted input by the user; The interception list acquisition module is used for carrying out self-adaptive encapsulation processing on the resource identifier to be intercepted to obtain a target interception list; The updating instruction acquisition module is used for constructing an interception list updating instruction containing the target interception list according to the target interception list; The control function state acquisition module is used for acquiring the network control function state of the browser; And the request interception module is used for sending the interception list updating instruction to the browser through the full duplex communication channel if the network control function state indicates that the network control function of the browser is started, and the browser is used for intercepting the network resource request according to the target interception list.
- 9. An electronic device comprising a processor, a memory and a program or instruction stored on the memory and executable on the processor, the program or instruction when executed by the processor implementing the method of any one of claims 1-7.
- 10. A readable storage medium, characterized in that it stores thereon a program or instructions, which when executed by a processor, implements the method according to any of claims 1-7.
Description
Network resource request interception method and device, electronic equipment and medium Technical Field The application belongs to the field of network request interception, and particularly relates to a network resource request interception method, a device, electronic equipment and a medium. Background In application scenarios such as Web (network) automation testing, crawler protection, advertisement filtering, privacy compliance, etc., it is generally required to prevent a browser from loading specific network resources, that is, to intercept specific network resource requests, so as to implement filtering or protection of specific content. In the prior art, the interception rule of the network resource request is usually loaded when the browser is started, cannot be dynamically modified during the operation of the browser, and can be validated only by restarting the browser after the interception rule is changed, so that the interception rule changing efficiency is reduced. In addition, in the prior art, interception of the network resource request can be realized only after the proxy server is additionally deployed, the root certificate is installed or the application store is used for auditing, so that the complexity of interception of the network resource request is increased, and additional security risks and operation and maintenance costs are introduced. Disclosure of Invention The embodiment of the application aims to provide a network resource request interception method, a network resource request interception device, electronic equipment and a medium. In a first aspect, an embodiment of the present application provides a method for intercepting a network resource request, which is applied to a network resource interception system, where the network resource interception system is connected to a browser in a communication manner through a full duplex communication channel, and the method includes: receiving a resource identifier to be intercepted input by a user; Performing self-adaptive encapsulation processing on the resource identifier to be intercepted to obtain a target interception list; Constructing an interception list updating instruction containing the target interception list according to the target interception list; Acquiring a network control function state of the browser; And if the network control function state indicates that the network control function of the browser is started, the interception list updating instruction is sent to the browser through the full duplex communication channel, and the browser is used for intercepting the network resource request according to the target interception list. Optionally, the step of adaptively encapsulating the resource identifier to be intercepted to obtain a target interception list includes: The method comprises the steps of obtaining an identification type of a resource identification to be intercepted, wherein the identification type comprises one of a null value, a character string, a list, a tuple and other types, and the other types are other identification types except the null value, the character string, the list and the tuple; If the identification type is the null value, packaging the resource identification to be intercepted as a null list, and taking the null list as a target interception list; If the identification type is the character string, the resource identification to be intercepted is packaged into a unit pixel list, and the unit pixel list is used as a target interception list; if the identification type is the list or the tuple, the resource identification to be intercepted is used as a target interception list; and if the identification type is the other type, generating type error prompt information according to the identification of the resource to be intercepted, and sending the type error prompt information to the user. Optionally, the step of constructing an interception list update instruction including the target interception list according to the target interception list includes: Performing de-duplication, sequencing and security verification on a plurality of to-be-intercepted resource identifiers in the target interception list to obtain a processed target interception list; if the number of the resource identifiers to be intercepted is greater than a preset number threshold in the processed target interception list, splitting the target interception list into a plurality of target interception sub-lists, and respectively constructing an interception list updating instruction according to the plurality of target interception sub-lists; If the number of the resource identifiers to be intercepted is smaller than or equal to the number threshold value in the target interception list, constructing an interception list updating instruction containing the target interception list according to the target interception list. Optionally, the method further comprises: If the initial state of the network co