A method for blocking XSS attacks under HTTPS protocol

By using ECC digital signature to verify the legitimacy of cookies under HTTPS protocol, the problem of XSS attacks under HTTPS is solved, and higher security and low computing overhead are achieved, avoiding the needs of third-party agents.

CN117375952BActive Publication Date: 2024-10-11JINHUA INST FOR ADVANCED STUDY (OFFICE OF THE LEADING GRP FOR THE PREPARATORY WORK OF JINHUA INST OF TECH)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311404742.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-27
Publication Date
2024-10-11
Estimated Expiration
2043-10-27

AI Technical Summary

Technical Problem

XSS attacks still exist under the HTTPS protocol, and the existing technology is difficult to effectively block, especially because the cookie mechanism is independent of the TLS protocol and cannot fully guarantee the security of cookie information.

Method used

The client certifies the identity by attaching an ECC digital signature to the requested cookie, the server performs identity authentication, and any cookies that fail to pass the identity authentication will be denied, thereby blocking the XSS attack. Specific methods include public and private key authentication between the client and the server, and elliptic curve encryption and digital signature algorithms to verify the legitimacy of cookies.

Benefits of technology

Effectively block fake cookie attacks, improve the security of the HTTPS protocol, authenticate through asymmetric key digital signature algorithm, verify the correctness and security of the protocol, does not require a third-party proxy, and has relatively high computing overhead and communication delays. Low.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117375952B_ABST
    Figure CN117375952B_ABST
Patent Text Reader

Abstract

The present invention relates to a blocking method for XSS attacks under HTTPS protocol, comprising: a client inputs initial credentials to make a login request, a server authenticates the initial credentials, and obtains server credentials including a first cookie parameter set and a first credential; the client authenticates the server credentials, obtains an encrypted session key and a digital signature, and constructs a second cookie parameter set with a digital signature; the server authenticates the second cookie parameter set, and if it is invalid, the login request is discarded; if it is valid, the encrypted session key is decrypted and stored to complete the login; the client creates a request containing a third cookie parameter set, the server authenticates the third cookie parameter set, and if it is invalid, the request is discarded; if it is valid, the request is encrypted, a ciphertext is generated and sent to the client, and the client decrypts the ciphertext through the session key. The present invention can block malicious user terminals from launching XSS attacks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of XSS attack technology under the HTTPS protocol on the web, and in particular to a method for blocking XSS attacks under the HTTPS protocol. Background Technology

[0002] Hypertext Transfer Protocol (HTTP) is a stateless, connectionless protocol. Because it doesn't require servers to retain information about requests, servers are unaware of previous requests and cannot identify requests from the same user. To track user state or information in web applications, HTTP cookies were introduced in RFC 2109. Cookies contain session information (such as a session identifier ID), are created by the server, and stored in the browser. For example, when a user logs into a website, the server responds with a cookie header containing a cookie ID, which the browser saves for later use. The browser attaches cookies to every request so the server can identify the user. While cookies have become the mainstream HTTP session management mechanism, they also introduce a series of security problems. By design, cookies are static and immutable throughout their lifespan. Therefore, if an attacker steals authentication cookies, they can impersonate the user associated with those cookies. However, using cookies as session authentication tokens increases vulnerabilities in web sessions. Cross-site scripting (XSS) attacks exploit these vulnerabilities. XSS is a programming-related flaw that occurs when user input data is not processed correctly. Attackers can exploit this vulnerability to inject unfiltered script code into web applications, leading to account takeover, session or cookie theft, and rerouting to the attacker's website when the parser processes the script. XSS is an injection attack that is present in approximately two-thirds of web applications, according to OWASP (Open Web Applications Security Project)'s 2021 list of the top 10 security risks.

[0003] HTTPS adds the Transport Layer Security (TLS) protocol to the HTTP protocol. HTTPS encrypts data, authenticates the identities of servers and clients, and checks data integrity in the protection protocol through TLS. However, because the cookie mechanism is independent of the TLS protocol, the security of cookie information cannot be completely guaranteed. XSS still threatens the security of HTTPS. To protect the information in cookies, researchers such as Dacosta proposed an OTC (one-time cookies) scheme to enhance the security of HTTPS. Instead of using a single static token to authenticate each request, the OTC scheme uses a session key to generate a unique token for each request. The OTC scheme uses symmetric encryption and shares a fixed key among all web application servers. A major weakness of this scheme is that it uses a fixed key to generate the key during the session; if an attacker cracks the key, this will directly lead to the compromise of one-time cookies. Researchers such as Sathiyaseeland introduced an RPS (Reverse Proxy Server) to generate and check OTCs, which can prevent adversaries from capturing session credentials. Researchers such as Prapty used RPS and COM (Cryptography Operations Module) to prevent session hijacking. Obviously, both methods require a third party to implement the OTC mechanism. He et al. proposed an OTC protocol based on OTP (one-time password), which generates dynamic keys based on hash chains to improve OTC security. However, the new OTC is more complex, and to overcome the shortcomings of existing OTC schemes, a method for blocking XSS attacks under the HTTPS protocol is urgently needed. Summary of the Invention

[0004] The purpose of this invention is to provide a method for blocking XSS attacks under the HTTPS protocol. The client proves its identity by attaching an ECC digital signature to the cookie in the request, while the server performs identity authentication. Any cookie that fails the authentication will be rejected by the server, thus blocking the XSS attack.

[0005] To achieve the above objectives, the present invention provides the following solution:

[0006] A method for blocking XSS attacks under HTTPS protocol includes:

[0007] The client enters initial credentials to make a login request. The server authenticates the initial credentials and obtains server credentials, wherein the server credentials include a first cookie parameter set and a first credential, wherein the first credential contains the server public key.

[0008] The client authenticates the server credentials, obtains the encrypted session key and digital signature, and constructs a second cookie parameter set based on the first cookie parameter set, wherein the second cookie parameter set carries a digital signature;

[0009] The server authenticates the second cookie parameter set. If the second cookie parameter set is invalid, the login request is discarded; if the second cookie parameter set is valid, the encrypted session key is decrypted and stored to complete the login.

[0010] The client creates a request containing a third cookie parameter set. The server authenticates the third cookie parameter set. If the third cookie parameter set is invalid, the request is discarded. If the third cookie parameter set is valid, the request is encrypted to generate ciphertext and sent to the client. The client decrypts the ciphertext using the session key. The third cookie parameter set contains information from the second cookie parameter set.

[0011] Furthermore, the initial credentials include the username and password used for login.

[0012] Further, the server authenticates the initial credentials, and obtaining server credentials includes:

[0013] The server authenticates the initial credentials based on the username and password, and constructs a first cookie parameter set φ1 = {cookieid, F...} p The construction method includes: selecting the elliptic curve E(F, a, b, P, n, H(·)}. p Let p be a prime number greater than 3, and a and b be numbers satisfying 4a 3 +27b 3 Let G(x,y) be a set of non-negative integers ≠ 0 (mod p) and less than p, where (x,y)∈F. p P is a base point on the elliptic curve, the order of P is a prime number n, and H(·) is the SHA-256 hash function;

[0014] Obtain server public key PK s Based on the server public key PK s Construct the first credential.

[0015] Furthermore, the client authenticates the server credentials to obtain the encrypted session key, including:

[0016] Client authentication includes the server's public key (PK). sThe first credential generates a random byte string as the session key K. s And based on the server public key PK s For the session key K s Perform encryption and obtain the encrypted session key E. PKs (K s ).

[0017] Furthermore, constructing a second cookie parameter set based on the first cookie parameter set includes:

[0018] Construct the client public key PK based on the first cookie parameter set. c and the corresponding key SK c ;

[0019] Based on the first cookie parameter set, and in combination with the key SK c Make timestamp T c Generate digital signature σ c ;

[0020] Combined with the client public key PK c and the digital signature σ c Construct a second cookie parameter set Φ2 = {cookieid, T} c PK c ,σ c (r,s)}.

[0021] Furthermore, a client public key PK is constructed based on the first cookie parameter set. c and the corresponding key SK c include:

[0022] Select a random integer d based on the first cookie parameter set. c ∈[1,n-1], calculate Q c =d c P, obtain the client public key PK c For Q c The key SK c For d c .

[0023] Furthermore, based on the first cookie parameter set, and in conjunction with the key SK c Make timestamp T c Generate digital signature σ c include:

[0024] S1.1 Select a random integer k∈[1,n-1] based on the first cookie parameter set;

[0025] S1.2 Calculate kP = (x1, y1), and convert x1 to an integer;

[0026] S1.3 Calculate r = x1 mod n. If r = 0, go to step S1.1 and select k again.

[0027] S1.4 Calculate SHA-256(T) c Convert the timestamp string to an integer h = H(T). c );

[0028] S1.5 Calculate s = k -1 (h+d c If s = 0, then proceed to step S1.1 and select k again;

[0029] S1.6 uses (r,s) as the timestamp T c The generated digital signature σ c .

[0030] Furthermore, the server authentication of the second cookie parameter set includes:

[0031] The server authenticates the cookieid in the second cookie parameter set. If the cookieid is invalid, the login request is discarded; if the cookieid is valid, the server authenticates the digital signature σ in the second cookie parameter set. c Authenticate the digital signature σ in the second cookie parameter set. c include:

[0032] S2.1 Check if r and s are integers and r, s ∈ [1, n-1]. If they are not integers, then the digital signature σ is... c Invalid; if it is an integer, proceed to step S2.2;

[0033] S2.2 Calculate SHA-256(T) c ), and convert the timestamp string into an integer h = H(T) c );

[0034] S2.3 Calculate u1 = h·s -1 mod n, u2=r·s -1 mod n;

[0035] S2.4 Calculate X(x1,y1)=u1P+u2Q c v = x1 mod n;

[0036] S2.5 If r = v, then the digital signature σ c Valid; otherwise, digital signature σ c invalid.

[0037] Furthermore, the client creates a request containing a third cookie parameter set, and the server authenticates the third cookie parameter set by:

[0038] The client uses the timestamp T from the second cookie parameter set. c and digital signatures c Construct the third cookie parameter set Φ3 = {cookieid, T c ,σ c (r,s)}, and create a request containing a third cookie parameter set, in which the server looks up Q. c Client public key PK c If Q c If it does not exist, then the digital signature σ c Invalid; if Q c If it exists, proceed to steps S2.1-S2.5.

[0039] The beneficial effects of this invention are as follows:

[0040] The method proposed in this invention prevents counterfeit cookies from responding to requests due to the lack of a valid digital signature, thus blocking malicious user-initiated XSS attacks. Compared to previous methods, the encryption method of this invention is secure, employing an asymmetric key digital signature algorithm to authenticate cookies and verifying the correctness and security of the protocol through the Scyther Tool. The XSS blocking method of this invention is universal, requiring no third-party proxy and having no limitations. The method of this invention is lightweight; through computational overhead analysis, the ciphertext is smaller compared to other methods, and the increase in transmission latency and communication overhead due to the addition of digital signatures is relatively low. Attached Figure Description

[0041] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0042] Figure 1 This is a schematic diagram of an XSS attack under the HTTPS protocol according to an embodiment of the present invention;

[0043] Figure 2 This is a flowchart of a method for blocking XSS attacks under the HTTPS protocol according to an embodiment of the present invention. Detailed Implementation

[0044] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0045] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0046] This embodiment provides a method for blocking XSS attacks under the HTTPS protocol, such as... Figure 1 , Figure 2 As shown, the HTTPS protocol uses the TLS protocol. The network includes two types of objects: client and server. After the client logs in for the first time using a username and password, it can subsequently initiate requests using cookies as credentials. The diagram illustrates the process of client C from logging in to receiving a request response, including the following steps:

[0047] Step 1: The client uses the username and password as credentials to log in to the webpage.

[0048] The client sends a GET request to the web application to log in;

[0049] The client enters their login credentials, including username and password.

[0050] The client waits for the page to update to check if the login was successful.

[0051] Step 2: The server authenticates the client's account credentials, generates a cookie parameter set, and sends the parameter set and certificate credentials containing the public key to the client.

[0052] The server authenticates the client's credentials based on the client's username and password.

[0053] The server constructs a cookie parameter set φ = {F} using the ECC algorithm. p ,a,b,P,n,H(·)}。 Select elliptic curve E(F p ), where p is a prime number greater than 3, and a and b are numbers satisfying 4a 3 +27b 3 Let G(x,y) be a set of non-negative integers ≠ 0 (mod p) and less than p, where (x,y)∈F. p P is a base point on an elliptic curve, and the order of P is a prime number n. The SHA-256 hash function H(·) is chosen.

[0054] The server generates a cookie ID for authenticated clients and adds it to the parameter set φ = {cookie ID, F}. p ,a,b,P,n,H(·)}.

[0055] The server will contain the public key PK. s The certificate and cookie parameter set φ are sent to the authenticated client.

[0056] Step 3: The client authenticates the server's credentials, generates a session key and digital signature, and sends the encrypted session key and digitally signed cookie to the server.

[0057] The certificate sent by the client authentication server.

[0058] The client generates a random byte string as the session key K. s .

[0059] The client uses the public key from the server certificate to perform a PK. s For K s Encryption is performed for E PKs (K s ).

[0060] The client generates a public key and its corresponding private key by following these steps:

[0061] (1) Select a random integer d c ∈[1,n-1];

[0062] (2) Calculate Q c =d c P;

[0063] (3) Client's public key PK c For Q c Private key SK c For d c .

[0064] The client follows these steps to make the timestamp T c Generate digital signature σ c :

[0065] (1) Select a random integer k∈[1,n-1];

[0066] (2) Calculate kP = (x1, y1), and convert x1 to an integer;

[0067] (3) Calculate r = x1 mod n. If r = 0, go back to step 1 and select k again.

[0068] (4) Calculate SHA-256(T) c), and convert the timestamp string into an integer h = H(T) c );

[0069] (5) Calculate s = k -1 (h+d c If s = 0, then proceed to step one and select k again;

[0070] (6) Use (r,s) as the timestamp T c Digital signature σ c ;

[0071] The client sends E PKs (K s ) and cookie{cookieid,T c, PK c, σ c (r,s)} is given to the server.

[0072] The key and signature generation algorithms are shown in Table 1.

[0073] Table 1

[0074]

[0075] Step 4: The server authenticates the client's cookie identity, decrypts the session key, and stores it.

[0076] The server authenticates the received cookie ID; if the cookie ID is invalid, the request is discarded.

[0077] The server checks the cookie and authenticates the signature σ according to the following steps. c (r,s) is used to authenticate the client's identity:

[0078] (1) Check if r and s are integers and r, s ∈ [1, n-1]. If they are not integers, the digital signature σc is invalid.

[0079] (2) Calculate SHA-256(T) c ), and convert the timestamp string into an integer h = H(T) c );

[0080] (3) Calculate u1 = h·s -1 mod n, u2=r·s -1 mod n;

[0081] (4) Calculate X(x1,y1)=u1P+u2Q c v = x1 mod n;

[0082] (5) If r = v, then the digital signature σ cValid; otherwise, digital signature σ c invalid.

[0083] The server uses the private key SK. s Decrypting E PKs (K s ) to obtain K s .

[0084] The server stores the session key K corresponding to the cookie ID. s PK with client public key c .

[0085] The cookie authentication algorithm is shown in Table 2.

[0086] Table 2

[0087]

[0088] Step 5: The client uses the timestamp to generate a digital signature, adds it to the cookie, and sends a request containing the cookie signature to the server.

[0089] The client is based on the timestamp T c and digital signatures c Construct cookie{cookieid,T c ,σ c (r,s)}.

[0090] The client sends a request to the server, which includes the generated cookie.

[0091] Step 6: The server authenticates the client's cookie identity and sends the data from the request to the authenticated client after encryption.

[0092] The server looks up the corresponding public key Q based on the received cookie ID. c If Q c If it does not exist, then the digital signature σ c Invalid; if Q c If it exists, then authenticate the signature σ according to steps (1)-(5) in step 4. c To authenticate the client's identity.

[0093] The server uses the session key K corresponding to the cookie ID. s The data in the encrypted request.

[0094] The server sends the encrypted message to the client.

[0095] Step 7: The client uses the session key to decrypt the received ciphertext.

[0096] The client uses K s Decrypt the received ciphertext.

[0097] In the technical method of the above embodiment, if a malicious user launches an XSS attack, that is, the request issued in step 5 is malicious code and is not a cookie generated by the digital signature authenticated in steps 1-4, the fake cookie does not have a valid digital signature and cannot pass the server's identity authentication to respond to the request, thus blocking the malicious user from launching an XSS attack.

[0098] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Various modifications and improvements made to the technical solutions of the present invention by those skilled in the art without departing from the spirit of the present invention should fall within the protection scope defined by the claims of the present invention.

Claims

1. A method for blocking XSS attacks under HTTPS protocol. It is characterized in that include: The client inputs initial credentials to make a login request, and the server authenticates the initial credentials and obtains server credentials, wherein the initial credentials include the user name and user password used for login, and the server credentials include a first cookie parameter set and a first credential, wherein the first credential includes a server public key; The server authenticates the initial credentials, and obtaining the server credentials includes: The server authenticates the initial credentials based on the user name and user password, and constructs a first cookie parameter set φ 1 ={cookieid,F p ,a,b,P,n,H(·)}, the construction method includes: selecting the elliptic curve E(F p ), p is a prime number greater than 3, a and b satisfy 4a 3 +27b 3 ≠0(mod p) and a non-negative integer less than p, G(x,y) is a group of points on the elliptic curve, (x,y)∈F p , P is a base point on the elliptic curve, the order of P is a prime number n, and H(·) is the SHA-256 hash function; Get the server public key PK s , based on the server public key PK s constructing the first credential; The client authenticates the server credentials, obtains the encrypted session key and digital signature, and constructs a second cookie parameter set based on the first cookie parameter set, wherein the second cookie parameter set carries a digital signature; The server authenticates the second cookie parameter set, and if the second cookie parameter set is invalid, discards the login request; if the second cookie parameter set is valid, decrypts and stores the encrypted session key, and completes the login; The client creates a request including a third cookie parameter set, and the server authenticates the third cookie parameter set. If the third cookie parameter set is invalid, the request is discarded. If the third cookie parameter set is valid, the data of the request is encrypted, a ciphertext is generated and sent to the client, and the client decrypts the ciphertext using the session key, wherein the third cookie parameter set includes the information in the second cookie parameter set.

2. According to the method for blocking XSS attacks under the HTTPS protocol according to claim 1, It is characterized in that The client authenticates the server credentials and obtains the encrypted session key including: The client authentication contains the server public key PK s The first credential generates a random byte string as the session key K s , and based on the server public key PK s The session key K s Encrypt and obtain the encrypted session key E PKs (K s ).

3. According to the blocking method of XSS attack under HTTPS protocol according to claim 1, It is characterized in that The client authenticates the server credentials and obtains the digital signature including: Based on the first cookie parameter set, the timestamp T c Generate digital signature σ c , specifically including: S1.1 Select a random integer k∈[1,n-1] based on the first cookie parameter set; S1.2 Calculate kP = (x 1 ,y 1 ), and x 1 Convert to integer; S1.3 Calculate r = x 1 modn, if r=0, go to step S1.1 and reselect k; S1.4 Calculate SHA-256(T c ), convert the timestamp string into an integer h = H (T c ); S1.5 Calculation of s=k -1 (h+d c r), if s=0, go to step S1.1 and reselect k; S1.6 Take (r,s) as the timestamp T c The generated digital signature σ c .

4. According to the method for blocking XSS attacks under the HTTPS protocol according to claim 1, It is characterized in that Constructing a second cookie parameter set based on the first cookie parameter set includes: Construct the client public key PK based on the first cookie parameter set c and the corresponding key SK c , and combined with the digital signature σ c Construct the second cookie parameter set Φ 2 ={cookieid,T c ,PK c ,σ c (r,s)}.

5. According to the method for blocking XSS attacks under the HTTPS protocol according to claim 4, It is characterized in that Construct the client public key PK based on the first cookie parameter set c and the corresponding key SK c include: Select a random integer d based on the first cookie parameter set c ∈[1,n-1], calculate Q c =d c P, obtain the client public key PK c Q c , the key SK c is d c .

6. According to the blocking method of XSS attack under HTTPS protocol as described in claim 4, It is characterized in that The second cookie parameter set for server authentication includes: The server authenticates the cookieid in the second cookie parameter set. If the cookieid is invalid, the login request is discarded; if the cookieid is valid, the digital signature in the second cookie parameter set is authenticated. c , authenticate the digital signature σ in the second cookie parameter set c include: S2.1 Check whether r and s are integers, and r,s∈[1,n-1]. If they are not integers, then the digital signature σ c Invalid; if it is an integer, go to step S2.2; S2.2 Calculate SHA-256(T c ), and convert the timestamp string into an integer h = H (T c ); S2.3 Calculation of u 1 =h·s -1 modn,u 2 = r·s -1 modn; S2.4 Calculate X(x 1 ,y 1 )=u 1 P+u 2 Q c , v = x 1 modn; S2.5 If r = v, then the digital signature σ c Valid; otherwise, the digital signature σ c invalid.

7. The method for blocking XSS attacks under the HTTPS protocol according to claim 6, It is characterized in that The client creates a request including a third cookie parameter set, and the server authenticates the third cookie parameter set including: The client uses the timestamp T in the second cookie parameter set c and digital signature σ c , construct the third cookie parameter set Φ 3 ={cookieid,T c ,σ c (r,s)} and creates a request containing a third cookie parameter set, in which the server looks for Q c The client public key PK c , if Q c does not exist, then the digital signature σ c Invalid; if Q c If yes, proceed to steps S2.1-S2.5.