Short link generation method, server, storage medium and program product
By introducing pseudo-random numbers and preset index calculation formulas, combined with a multi-level security review mechanism, the problems of high repetition rate and poor security of short links are solved, and personalized, secure and reliable short link generation is realized, ensuring efficient management and unified storage.
Patent Information
- Application Number
- CN202411552096.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-01
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2044-11-01
AI Technical Summary
Due to the fixedness of the hash function, the same long URL always generates the same short link, with high repetition rate and uncontrollable security and quality.
By introducing pseudo-random numbers and preset index calculation formulas, combining a multi-level security review mechanism, dynamic short links are generated, and information entropy evaluation and distributed storage architecture are adopted to ensure the uniqueness and security of short links.
It effectively reduces the duplication rate of short links, improves security and availability, realizes personalized, secure and reliable short link generation, and ensures efficient management and unified storage.
Smart Images

Figure CN119441643B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet information technology, and in particular to a short link generation method, server, storage medium and program product. Background Art
[0002] With the rapid development of the internet, web links are becoming increasingly longer. However, long web links are difficult to remember, read, and manually enter, especially in social media, text messages, and other environments with character limits. Therefore, short link services have emerged to simplify the link sharing process, improving user experience and dissemination efficiency.
[0003] The relevant short link generation technology is usually that the server puts the long URL into a preset hash function to generate a hash value of fixed length. The server then selects a part of the hash value, usually the first or middle few characters, as the identifier of the short link, thereby quickly providing the short link to the user.
[0004] Although existing short link generation methods can effectively shorten URLs, due to the fixed nature of the hash function, the same long URL always generates the same short link, resulting in a high repetition rate of short links, which can easily cause confusion when used on a large scale. Summary of the Invention
[0005] The present application provides a short link generation method, server, storage medium and program product for improving the security of short link generation.
[0006] In a first aspect, the present application provides a short link generation method, which is applied to a server, and the method includes: obtaining user information, current time and original web page address; inputting the original web page address into a preset hash function to obtain a hash value of a first length; generating a pseudo-random number based on the user information and the current time; inputting the pseudo-random number into a preset index calculation formula to obtain a valid index; based on the valid index, selecting consecutive characters of a second length from the hash value as a hash short code, the first length being greater than the second length; performing a security review on the hash short code to ensure that the hash short code does not contain preset sensitive words, preset easily confused characters and / or preset known vulnerabilities; if the result of the security review is safe, encoding the hash short code according to preset link generation parameters to obtain a final short link, and the preset link generation parameters are used to represent the structure and properties of the short link generation.
[0007] By adopting the above technical solution, first, the server introduces a pseudo-random number based on user information and the current time, breaking the limitation of the traditional short link generation method that the same long URL always generates the same short link. Even for the same original web page address, different short links can be generated when accessed at different times or by different users, effectively reducing the repetition rate of short links and improving security. Secondly, the server performs a security review of the hash short code to ensure that the generated short link does not contain preset sensitive words, preset easily confused characters and / or preset known vulnerabilities, thereby improving the security and availability of the short link. Finally, the server standardizes the encoding of the hash short code through preset link generation parameters, ensuring that the generated short link has a unified structure and format, which is convenient for unified management and user use.
[0008] In conjunction with some embodiments of the first aspect, in some embodiments, the preset index calculation formula is: Wherein, I represents the valid index, R represents the pseudo-random number, and p represents a preset prime number. Represents the preset golden section constant, L represents the first length of the hash value, Indicates floor operation, and mod indicates modulo operation.
[0009] By adopting the above technical solution, the server achieves efficient and uniform index generation through the preset index calculation formula. Introducing the preset prime number p as the modulus can provide good hashing characteristics and avoid periodic distribution; using the golden section constant Using this as a multiplier creates a uniform distribution across the number axis, reducing the probability of collisions. The floor rounding operation and the final modulo-L operation ensure that the generated valid index remains within the valid range. This calculation method not only offers low computational overhead and high efficiency, but also ensures that the generated valid index possesses good randomness and uniformity, resulting in a more balanced distribution of short hash codes selected from the hash value, further reducing the probability of duplication in short links.
[0010] In combination with some embodiments of the first aspect, in some embodiments, the hash short code is subjected to a security review to ensure that the hash short code does not contain preset sensitive words, preset easily confused characters and / or preset known vulnerabilities, specifically including: matching the hash short code with a preset sensitive word library to determine whether the preset sensitive words exist; checking whether the preset easily confused characters exist in the hash short code; inputting the hash short code into a preset vulnerability identification model to determine whether the preset known vulnerability exists; if the preset sensitive words, the preset easily confused characters and / or the preset known vulnerabilities do not exist in the hash short code, the result of the security review is safe; if the preset sensitive words, the preset easily confused characters and / or the preset known vulnerabilities exist in the hash short code, the result of the security review is unsafe.
[0011] By adopting the above technical solution and establishing a triple security review mechanism, the security and availability of short links are fully guaranteed. First, the server matches the hash short code with a preset sensitive word library to prevent the generated short link from containing inappropriate content or banned words. Second, the server determines whether there are preset easily confused characters in the hash short code to avoid generating confusing or difficult-to-identify short links, thereby improving the user experience. Then, the server identifies potential security vulnerabilities in the hash short code through a preset vulnerability identification model, effectively preventing possible security threats. This multi-level security review mechanism can promptly detect and filter out unqualified short links, ensuring that the final generated short link is both safe and reliable, and easy to identify and use, significantly improving the quality and security of the short link service.
[0012] In combination with some embodiments of the first aspect, in some embodiments, if the result of the security review is safe, the hash short code is encoded according to the preset link generation parameters to obtain the final short link, specifically including: determining the domain name prefix and path separator based on the preset link generation parameters; splicing the domain name prefix, the path separator and the hash short code in a preset order; URL encoding the spliced string; and combining the encoded string with a preset protocol identifier to obtain the final short link.
[0013] By adopting the above technical solution, the server unifies the short link generation structure based on preset link generation parameters. The domain name prefix and path separator can ensure that the generated short links have a unified format and hierarchical structure; splicing in a preset order can ensure the orderliness of the various components of the short link; URL encoding processing can solve the compatibility issues of special characters, allowing short links to be used normally in various environments; combining the encoded string with the preset protocol identifier can ensure the integrity and availability of the short link. This standardized encoding scheme not only improves the readability and ease of use of short links, but also facilitates the unified management and maintenance of short links, improving the compatibility and reliability of short links in different platforms and scenarios.
[0014] In combination with some embodiments of the first aspect, in some embodiments, after the step of performing a security review on the hash short code to ensure that the hash short code does not contain preset sensitive words, preset easily confused characters and / or preset known vulnerabilities, the method also includes: if the result of the security review is unsafe, determining the cause of the insecurity; based on the cause of the insecurity, selecting a corresponding correction strategy from a preset correction strategy library; according to the correction strategy, correcting the hash short code to obtain an optimized hash short code.
[0015] By employing the above technical solution, the server effectively handles situations where security review fails. Specifically, when a short link presents a security risk, the server first determines the cause of the insecurity. Based on the different causes, the server selects the most appropriate remediation strategy from a preset remediation strategy library and then executes the corresponding remediation strategy to optimize the problematic hash short code into a more secure form. This adaptive remediation mechanism not only improves the success rate of short link generation but also ensures that even in the event of a security issue, the server can still generate a compliant short link through optimization, thereby improving the reliability of the short link generation method.
[0016] In combination with some embodiments of the first aspect, in some embodiments, if the result of the security review is safe, after the step of encoding the hash short code according to the preset link generation parameters to obtain the final short link, the method also includes: calculating the information entropy of the final short link; when the information entropy is greater than or equal to the preset information entropy threshold, storing the final short link, the original web page address, the user information and the current time in a distributed database; when the information entropy is less than the preset information entropy threshold, processing the final short link according to the preset information enhancement algorithm to obtain an optimized short link.
[0017] By adopting the above technical solution, the server introduces a short link quality assessment mechanism based on information entropy. This mechanism measures the randomness and complexity of a short link by calculating its information entropy. When the information entropy is greater than or equal to a preset entropy threshold, the short link is deemed sufficiently random and secure. The server then stores the information along with related information in a distributed database to ensure data reliability and traceability. When the information entropy is less than the preset entropy threshold, the server activates an information enhancement algorithm to optimize the short link quality.
[0018] In combination with some embodiments of the first aspect, in some embodiments, the information entropy of the final short link is calculated, specifically including: counting the total number of characters in the final short link and the number of occurrences of each character; dividing the number of occurrences of each character by the total number of characters in the final short link to obtain the probability of occurrence of each character; inputting the probability of occurrence of each character into a preset information entropy calculation formula to obtain the information entropy of the final short link, and the preset information entropy calculation formula is: H = -∑[P(si)*log2(p(si))] wherein H represents the information entropy, P(si) represents the probability of occurrence of each character, and si represents each character.
[0019] By adopting the above technical solution, the server determines the information entropy of the final short link based on the preset information entropy calculation formula, thereby accurately reflecting the randomness and information density of the final short link, providing reliable data support for the quality control and optimization of the short link, and effectively improving the scientificity and reliability of the short link generation method.
[0020] In a second aspect, an embodiment of the present application provides a server, comprising: one or more processors and a memory; the memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code comprising computer instructions, the one or more processors calling the computer instructions to enable the server to execute the method described in the first aspect and any possible implementation of the first aspect.
[0021] In a third aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on a server, enables the server to execute the method described in the first aspect and any possible implementation of the first aspect.
[0022] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium comprising instructions. When the instructions are executed on a server, the server executes the method described in the first aspect and any possible implementation of the first aspect.
[0023] It is understandable that the server provided in the second aspect, the computer program product provided in the third aspect, and the computer storage medium provided in the fourth aspect are all used to execute the methods provided in the embodiments of the present application. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods and will not be repeated here.
[0024] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:
[0025] 1. Due to the adoption of a dynamic hash generation mechanism based on user information and current time, combined with a multi-level security review mechanism, even for the same original web page address, different secure and reliable short links can be generated, effectively solving the technical problems of high short link repetition rate, poor security, and uncontrollable quality in related technologies, thereby realizing the personalization, security and reliability of the short link generation method.
[0026] 2. Due to the use of a preset index calculation formula and a quality assessment mechanism based on information entropy, combined with an intelligent correction strategy, the generated short links can be guaranteed to have good randomness and uniformity, effectively solving the technical problems of uneven distribution of short links, difficult quality quantification, and single optimization means in related technologies, thereby realizing the scientific, standardized and intelligent short link generation process.
[0027] 3. Due to the adoption of a distributed storage architecture and a complete data association mechanism, combined with standardized preset link generation parameters, it is possible to achieve reliable mapping and efficient management of short links and original information, effectively solving the technical problems of decentralized data storage, poor correlation, and difficulty in unified management in related technologies, thereby achieving high availability, traceability, and maintainability of short link services. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 This is a flowchart of a method for generating a short link in an embodiment of the present application;
[0029] Figure 2 This is another flowchart of the method for generating a short link in an embodiment of the present application;
[0030] Figure 3 This is a schematic diagram of the physical device structure of the server in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The terms used in the following examples of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification of the present application, the singular expressions "a", "an", "above", "the", and "this" are intended to include plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in the present application refers to any or all possible combinations of one or more of the listed items.
[0032] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of the technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.
[0033] For ease of understanding, the application scenarios of the embodiments of the present application are introduced below.
[0034] Xiaolin is a food blogger who frequently posts food reviews on social media platforms. One day, she wanted to share an in-depth review of a Michelin-rated restaurant. The original link was "https: / / www.weiliao.com / food / review / michelin / 2024 / shanghai / restaurant / 158764?author=xiaolin&content=full&photos=gallery&comments=true&rating=5&visit_date=20240315&meal_type=dinner." However, social media platforms limit each post to 280 characters, and Xiaolin also needs to include her own comment. This makes it impossible to post both a detailed food review and a complete link within the 280-character limit. Therefore, social media platforms urgently need a solution that can shorten link length while ensuring security and reliability.
[0035] The following is a description of the process of the method provided by this implementation. Figure 1 , which is a flow chart of the short link generation method in an embodiment of the present application.
[0036] S101, obtaining user information, current time and original web page address;
[0037] Among them, user information refers to a set of identifying data generated when a user accesses a platform, application, or system, including the user's unique identifier (such as user ID, session ID), access credentials (such as cookies, tokens), terminal information (such as device type, operating system, browser version), and network characteristics (such as IP address, geographic location, operator information), etc.; the current time refers to the system time when the server receives the short link generation request, usually expressed in the form of a Unix timestamp, accurate to milliseconds, to ensure the timing and uniqueness of the short link generation process; the original web page address is used to represent the complete URL that needs to be converted into a short link, and its structure usually includes a protocol header (such as http: / / , https: / / ), a domain name (such as www.example.com), a path (such as / path / to / page), a query parameter (such as ?key=value), and an anchor (such as #section).
[0038] The server performs this step upon receiving a short link generation request initiated by a user. Specifically, first, the server verifies the legitimacy of the received short link generation request, including checking the request method (GET / POST), the integrity of the request header fields, and the correctness of the content type. The server then extracts user information from the request header fields, such as checking the Authorization header to obtain the access token, obtaining session information from the cookie, obtaining client information from the User-Agent, and obtaining the IP address from the X-Forwarded-For or Remote-Address. Next, the server calls the system clock to obtain the current time, and performs time zone conversion and format standardization. Finally, the server parses the original web page address from the parameters of the short link generation request and performs URL format verification, including checking the URL's legitimacy (whether it complies with RFC standards), accessibility (whether it can be parsed and accessed normally), and security (whether it contains malicious code or redirects). For short link generation requests that do not meet the requirements, the server will return a corresponding error message.
[0039] S102: Input the original webpage address into a preset hash function to obtain a hash value of a first length;
[0040] Among them, the preset hash function refers to a cryptographic hash algorithm that can map input data of arbitrary length to a fixed-length output. Commonly used ones include MD5 (output 128 bits), SHA-1 (output 160 bits), SHA-256 (output 256 bits), etc. It has the characteristics of one-way (input cannot be inferred from output), collision resistance (the probability of different inputs producing the same output is extremely low) and avalanche effect (slight changes in input lead to significantly different outputs); the first length refers to the character length of the hash value output by the preset hash function, such as MD5 outputs 32 hexadecimal characters, and SHA-256 outputs 64 hexadecimal characters; the hash value is used to represent the fixed-length string obtained after calculation by the preset hash function, usually expressed in hexadecimal form, and used in the subsequent short link generation process.
[0041] The server performs this step after completing the acquisition and verification of the original web page address. Specifically, first, the server standardizes the original web page address, including removing extra spaces and special characters in the URL, unifying the uppercase and lowercase formats, processing relative paths, and normalizing the order of query parameters. Then, the server converts the standardized URL string into a byte array as the input of the preset hash function. Next, the server calls the preset hash function to calculate the input. During this process, the server may use salting (adding additional random data) to increase the uniqueness of the hash result. Finally, the server converts the output of the preset hash function into a hexadecimal string and verifies whether the output length meets the expectation (i.e., the first length).
[0042] S103, generating a pseudo-random number according to the user information and the current time;
[0043] Among them, pseudo-random numbers refer to seemingly random but actually reproducible numerical sequences generated by deterministic algorithms. Their random properties are sufficient to meet the needs of most application scenarios. The process of generating pseudo-random numbers based on user information and current time refers to the calculation process of converting input data (seed) into pseudo-random numbers, usually using standard algorithms such as the linear congruential method and the Mersenne twister algorithm. The seed refers to the initial data that initializes the pseudo-random number generator.
[0044] The server executes this step after obtaining valid user information and the current time. Specifically, the server first performs bitwise operations on the numerical data in the user information (such as the numerical representation of the user ID and IP address) and the current time to generate a 64-bit initial seed. The server then performs cryptographic hashing on this initial seed to increase its entropy value. The server then inputs the processed seed into a preset pseudo-random number generator for initialization. Finally, multiple rounds of iterative calculations are performed to generate the required pseudo-random numbers.
[0045] S104: Input the pseudo-random number into a preset index calculation formula to obtain a valid index;
[0046] Among them, the preset index calculation formula refers to a mathematical expression that maps pseudo-random numbers to a specific range, which is used to optimize the distribution characteristics of the index; the valid index refers to the starting position identifier of the characters intercepted from the hash value, and its value range must be between 0 and "the first length minus the second length".
[0047] The server performs this step after obtaining the pseudo-random number. Specifically, first, the server limits the pseudo-random number to a reasonable range through modular operation. The server can use a larger preset prime number (such as 2^31-1) as the modulus to obtain better distribution characteristics; then, the server multiplies the result by the golden section constant (approximately 0.618034) and rounds it up. This step can significantly improve the distribution uniformity of the index; then, the server performs a modular operation on the result again to make it fall within the valid index range, with the upper limit of the range being "the first length minus the second length"; finally, the server verifies the validity of the calculation result to ensure that the array does not cross the bounds. The entire calculation process needs to handle special cases such as numerical overflow and division by zero, and retry when necessary.
[0048] Optionally, in general, the preset index calculation formula is:
[0049]
[0050] Wherein, I represents the valid index, R represents the pseudo-random number, and p represents a preset prime number. Represents the preset golden section constant, L represents the first length of the hash value, Indicates floor operation, and mod indicates modulo operation.
[0051] S105. Based on the valid index, select consecutive characters of a second length from the hash value as a short hash code, where the first length is greater than the second length;
[0052] Among them, the second length represents the expected number of characters in the identifier part of the final short link, which is usually 6 to 8. The second length must ensure that the encoding space is large enough and the short link is short enough; continuous characters refer to a continuous character sequence starting from the position corresponding to the valid index in the hash value, and the original relative position relationship between the characters is required to be maintained; the hash short code is used to represent a fixed-length character string extracted from the complete hash value.
[0053] The server performs this step after obtaining a valid index. Specifically, first, the server verifies whether the combination of the valid index and the second length will cause an out-of-bounds condition, that is, to ensure that the "valid index + second length" does not exceed the total length of the hash value (that is, the first length); then, the server uses a string interception function to continuously intercept characters of the second length starting from the position corresponding to the valid index of the hash value; then, the server normalizes the intercepted string, including unifying the case of characters, replacing special characters, removing ambiguous characters, etc.; finally, the server verifies the length of the intercepted result to ensure that the length of the obtained hash short code is consistent with the expected (second length). If an exception occurs during the interception process, the server will record the error information and handle it accordingly according to the preset error handling strategy.
[0054] S106. Perform a security review on the hash short code to ensure that the hash short code does not contain preset sensitive words, preset easily confused characters, and / or preset known vulnerabilities;
[0055] Among them, security review refers to a series of inspection processes used to evaluate the security of hash short codes, including sensitive word detection, easily confused character detection, known vulnerability detection, etc.; sensitive words refer to a set of phrases that are not allowed to appear in short links, including banned words, insulting words, violent words, etc.; easily confused characters refer to character combinations that are visually confusing, such as "0" and "O", "1" and "l", etc.; known vulnerabilities refer to discovered or recorded short link generation patterns or character combinations that may be maliciously exploited.
[0056] The server executes this step immediately after generating the hash code. Specifically, first, the server loads the preset security check rules, including a sensitive word library, a table of easily confused characters, and a known vulnerability knowledge base. Then, the server uses a multi-pattern matching algorithm (such as an AC automaton) to scan the hash code for sensitive words to check whether it contains inappropriate content. Next, the server uses a regular expression engine to check whether there are potential security vulnerability patterns in the hash code. Finally, the server checks whether the hash code contains easily confused characters.
[0057] S107: If the result of the security review is safe, the hash short code is encoded according to the preset link generation parameters to obtain a final short link. The preset link generation parameters are used to represent the structure and attributes of the short link generation.
[0058] Among them, the preset link generation parameters refer to the configuration information used to build a complete short link, including the domain name of the short link service (such as "t.cn"), protocol type (such as "https"), path prefix, separator, etc.; encoding refers to the standardized process of converting the hash short code into a legal URL format, which requires processing special characters and reserved characters; the final short link refers to the short URL generated by the server that can be directly accessed and complies with the URL specification standards.
[0059] The server performs this step after the hash short code passes the security review. Specifically, first, the server reads the various parameters required for short link generation from the configuration information, including the service domain name, protocol type, path structure, etc., which are not limited here; then, the server URL encodes the hash short code to ensure that all characters are URL-safe. If necessary, the server can also perform Base64 encoding or other custom encoding; then, the server splices the encoded hash short code with other parameters (such as service domain name, path prefix) according to the predefined format template to construct a complete URL structure; then, the server normalizes the generated URL to ensure compliance with RFC standards; finally, the server performs usability verification, including checking whether the URL length is appropriate, whether it contains illegal characters, and whether it complies with DNS specifications. The entire generation process needs to consider the compatibility of the URL to ensure that it can be used normally in different clients and protocols. If the generated URL does not meet the requirements, the server will make appropriate adjustments or regenerate it.
[0060] Optionally, in general, if the result of the security review is safe, the hash short code is encoded according to the preset link generation parameters, and the final short link can be obtained by the following method:
[0061] The domain name prefix and path separator are determined based on the preset link generation parameters; the domain name prefix, the path separator and the hash short code are spliced in a preset order; the spliced string is URL-encoded; and the encoded string is combined with a preset protocol identifier to obtain the final short link.
[0062] By adopting the above technical solution, first, the server introduces a pseudo-random number based on user information and the current time, breaking the limitation of the traditional short link generation method that the same long URL always generates the same short link. Even for the same original web page address, different short links can be generated when accessed at different times or by different users, effectively reducing the repetition rate of short links and improving security. Secondly, the server performs a security review of the hash short code to ensure that the generated short link does not contain preset sensitive words, preset easily confused characters and / or preset known vulnerabilities, thereby improving the security and availability of the short link. Finally, the server standardizes the encoding of the hash short code through preset link generation parameters, ensuring that the generated short link has a unified structure and format, which is convenient for unified management and user use.
[0063] The following is a more detailed description of the process of the method provided by this implementation. Figure 2 , is another flow chart of the short link generation method in an embodiment of the present application.
[0064] S201, obtaining user information, current time and original web page address;
[0065] For details, please refer to step S101, which will not be described in detail here.
[0066] S202: Input the original webpage address into a preset hash function to obtain a hash value of a first length;
[0067] For details, please refer to step S102, which will not be described again here.
[0068] S203, generating a pseudo-random number according to the user information and the current time;
[0069] For details, please refer to step S103, which will not be described again here.
[0070] S204: Input the pseudo-random number into a preset index calculation formula to obtain a valid index;
[0071] For details, please refer to step S104, which will not be described again here.
[0072] S205. Based on the valid index, select consecutive characters of a second length from the hash value as a short hash code, where the first length is greater than the second length;
[0073] For details, please refer to step S105, which will not be described again here.
[0074] S206: Match the hash short code with a preset sensitive word library to determine whether the preset sensitive word exists;
[0075] Among them, the preset sensitive word library refers to a data set containing a variety of words that are not suitable to appear in short links, usually including politically sensitive words, violent words, pornographic words, discriminatory words and other categories; matching refers to the calculation process of using a string matching algorithm to check whether the hash short code contains preset sensitive words.
[0076] The server executes this step immediately after obtaining the hash short code. Specifically, first, the server loads the most recently updated preset sensitive word library to ensure the timeliness of the sensitive word data; then, the server preprocesses the preset sensitive word library, including establishing a dictionary tree (Trie tree) or AC automaton to optimize matching efficiency; then, the server converts the hash short code to a unified format (such as converting all to lowercase) to ensure matching accuracy; then, the server uses the optimized matching algorithm to scan the hash short code, while processing the matching of variant words (such as homophones and similar characters); finally, the server records the location and content of all matched preset sensitive words.
[0077] S207: Check whether the preset easily confused character exists in the hash short code;
[0078] Among them, easily confused characters refer to a set of characters that are visually easily mistaken for other characters, including confusion between numbers and letters (such as 0 and O, 1 and l, 5 and S), similar letter combinations (such as rn and m), etc.
[0079] The server executes this step immediately after obtaining the hash short code. Specifically, first, the server loads a preset easily confused character comparison table, which contains all easily confused character combinations that need to be checked; then, the server traverses the hash short code at the character level, checking whether each character belongs to an easily confused character combination; then, the server analyzes whether the combination of adjacent characters poses a visual confusion risk, such as checking whether "rn" may be mistaken for "m"; then, the server calculates the easily confused risk score of the entire hash short code according to the preset easily confused risk scoring rules; finally, the server determines whether the preset easily confused characters exist in the hash short code based on the easily confused risk score.
[0080] S208: Input the hash code into a preset vulnerability identification model to determine whether the preset known vulnerability exists;
[0081] Among them, the preset vulnerability identification model is used to identify string patterns that may pose security risks; known vulnerabilities refer to security threat types that have been discovered and recorded, including SQL injection patterns, XSS attack patterns, command injection patterns, etc.
[0082] The server executes this step immediately after obtaining the hash code. Specifically, the server first loads a preset vulnerability identification model, which typically uses deep learning or ensemble learning methods and has been specially trained for various preset known vulnerabilities. The server then extracts features from the hash code, including character-level statistical features, n-gram features, and semantic features. The server then inputs the extracted features into the preset vulnerability identification model for inference, determining whether the hash code contains any preset known vulnerabilities.
[0083] S209: If the hash short code does not contain the preset sensitive words, the preset easily confused characters, and / or the preset known vulnerabilities, the result of the security review is safe.
[0084] If it is determined through steps S206, S207, and S208 that there are no preset sensitive words, preset easily confused characters, and / or preset known vulnerabilities in the hash short code, then the result of the security review performed by the server on the hash short code is that it is safe.
[0085] S210: If the result of the security review is safe, the hash short code is encoded according to the preset link generation parameters to obtain a final short link, where the preset link generation parameters are used to represent the structure and attributes of the short link generation;
[0086] For details, please refer to step S107, which will not be described in detail here.
[0087] S211. Calculate the information entropy of the final short link;
[0088] Among them, information entropy is a mathematical indicator used to measure the complexity and randomness of information in short links, and is used to evaluate the difficulty of guessing or brute-forcing short links; the calculation method refers to the specific mathematical formula used to obtain information entropy, which is usually based on Shannon's information entropy theory.
[0089] The server executes this step immediately after obtaining the final short link. Specifically, the server first decomposes the final short link by character and counts the frequency of each character. Then, the server calculates the information content of each character. Finally, the server accumulates the information content of all characters to obtain the overall information entropy.
[0090] Optionally, in general, the information entropy of the final short link can be calculated by: counting the total number of characters in the final short link and the number of occurrences of each character; dividing the number of occurrences of each character by the total number of characters in the final short link to obtain the occurrence probability of each character; inputting the occurrence probability of each character into a preset information entropy calculation formula to obtain the information entropy of the final short link, and the preset information entropy calculation formula is:
[0091] H=-∑[P(si)*log2(p(si))]
[0092] Among them, H represents the information entropy, P(si) represents the occurrence probability of each character, and si represents each character.
[0093] S212: When the information entropy is greater than or equal to the preset information entropy threshold, the final short link, the original webpage address, the user information, and the current time are stored in a distributed database;
[0094] Among them, the preset information entropy threshold refers to the pre-set minimum information entropy value, which is used to ensure that the short link has sufficient randomness and security; the distributed database refers to a distributed storage system used to store short link related information, which has high availability and scalability.
[0095] The server performs this step after calculating the information entropy of the final short link. Specifically, the server first determines the data records to be stored, including the final short link, the original webpage address, user information, and the current time. The server then selects the optimal data sharding strategy, determining which database node the data should be stored on. The server then executes a distributed transaction to ensure data consistency across all database nodes. Simultaneously, the server updates relevant indexes and caches to optimize subsequent query performance.
[0096] S213: When the information entropy is less than the preset information entropy threshold, the final short link is processed according to a preset information enhancement algorithm to obtain an optimized short link;
[0097] The server executes this step when it finds that the information entropy of the final short link is insufficient. Specifically, first, the server analyzes the reasons for the insufficient information entropy of the final short link, such as the characters are too concentrated or there are obvious patterns; then, the server selects the corresponding enhancement strategy according to different reasons, which may include: inserting random characters in specific positions, adjusting the frequency of character appearance, disrupting the order of characters, etc.; then, the server performs the selected enhancement operation while ensuring that the basic usability of the final short link is not destroyed; then, the server recalculates the information entropy of the enhanced short link to verify whether it reaches the preset information entropy threshold; if it still does not reach the preset information entropy threshold, multiple rounds of optimization are required until the preset information entropy threshold is reached. The entire enhancement process needs to maintain the readability and ease of use of the short link while improving randomness, and avoid excessive complexity.
[0098] S214. If the hash short code contains the preset sensitive words, the preset easily confused characters, and / or the preset known vulnerabilities, the result of the security review is unsafe.
[0099] If it is determined through steps S206, S207, and S208 that the hash short code contains preset sensitive words, preset easily confused characters, and / or preset known vulnerabilities, then the result of the security review performed by the server on the hash short code is that it is unsafe.
[0100] S215. If the result of the safety review is unsafe, determine the cause of the unsafety;
[0101] The server immediately executes this step after determining that the security review result is unsafe. Specifically, the server analyzes the detailed security review log and extracts the reasons for the insecurity. The reasons for insecurity refer to the types of issues that caused the hash short code to be judged unsafe, including sensitive word triggers, character confusion risks, security vulnerabilities, etc.
[0102] S216. Based on the insecurity reason, select a corresponding correction strategy from a preset correction strategy library;
[0103] Among them, the correction strategy library refers to a knowledge base containing various solutions to security issues, providing corresponding processing methods for different problem categories; the correction strategy refers to the specific operation plan used to solve specific problem categories, including character replacement, regeneration, position adjustment and other methods.
[0104] The server performs this step after determining the cause of the insecurity. Specifically, the server first queries the preset remediation strategy library based on the problem category to obtain all possible remediation strategies. The server then screens these remediation strategies to eliminate those that may cause new problems, such as avoiding replacement solutions that create new, easily confused characters. The server then evaluates the success probability and implementation cost of each remediation strategy and selects the optimal one. If multiple problem categories exist, a comprehensive remediation plan is developed to ensure that the individual remediation actions do not interfere with each other.
[0105] S217: According to the correction strategy, the hash short code is corrected to obtain an optimized hash short code.
[0106] Among them, correction refers to the specific operational process of improving the hash short code according to the selected correction strategy; optimized hash short code refers to the new hash short code after correction, which needs to meet both security and availability requirements.
[0107] The server performs this step after selecting a remediation strategy. Specifically, the server first creates a copy of the original hash short code to ensure that the remediation process can be rolled back. Then, the server performs various remediation operations in the order defined in the remediation strategy, such as replacing characters in specific positions, adjusting the character order, and regenerating partial sequences. The server then immediately verifies the results of each remediation operation to ensure that the remediation has not introduced new issues. For complex remediation operations, the server may need to perform multiple iterations. Finally, the server performs a complete security review of the optimized hash short code to ensure that all issues have been resolved.
[0108] Because it adopts a dynamic hash generation mechanism based on user information and current time, combined with a multi-level security review mechanism, different safe and reliable short links can be generated even for the same original web page address, effectively solving the technical problems of high short link repetition rate, poor security and uncontrollable quality in related technologies, and thus realizing the personalization, security and reliability of the short link generation method.
[0109] By adopting a preset index calculation formula and a quality assessment mechanism based on information entropy, combined with an intelligent correction strategy, the generated short links can be guaranteed to have good randomness and uniformity, effectively solving the technical problems of uneven distribution of short links, difficult quality quantification, and single optimization means in related technologies, thereby realizing the scientific, standardized and intelligent short link generation process.
[0110] Due to the adoption of a distributed storage architecture and a complete data association mechanism, combined with standardized preset link generation parameters, it is possible to achieve reliable mapping and efficient management of short links and original information, effectively solving the technical problems of scattered data storage, poor correlation, and difficulty in unified management in related technologies, thereby achieving high availability, traceability and maintainability of short link services.
[0111] The following describes the server in the embodiment of the present invention from the perspective of hardware processing. Figure 3 , is a schematic diagram of a physical device structure of a server in an embodiment of the present application.
[0112] It should be noted that Figure 3 The structure of the server shown is only an example and should not limit the functions and scope of use of the embodiments of the present invention.
[0113] like Figure 3 As shown, the server includes a central processing unit (CPU) 301, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 302 or the program loaded from the storage part 308 to the random access memory (RAM) 303, such as executing the method described in the above embodiment. Various programs and data required for system operation are also stored in the RAM 303. The CPU 301, ROM 302 and RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0114] The following components are connected to the I / O interface 305: an input section 306 including an audio input device, a push button switch, and the like; an output section 307 including a liquid crystal display (LCD), an audio output device, an indicator light, and the like; a storage section 308 including a hard disk and the like; and a communication section 309 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to the I / O interface 305 as needed. Removable media 311, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 310 as needed, so that computer programs read therefrom can be installed into the storage section 308 as needed.
[0115] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product that includes a computer program carried on a computer-readable medium, the computer program including a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 309 and / or installed from a removable medium 311. When the computer program is executed by the central processing unit (CPU) 301, the various functions defined in the present invention are performed.
[0116] It should be noted that specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0117] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. Each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings.
[0118] Specifically, the server of this embodiment includes a processor and a memory. The memory stores a computer program. When the computer program is executed by the processor, the short link generation method provided in the above embodiment is implemented.
[0119] As another aspect, the present invention further provides a computer-readable storage medium, which may be included in the server described in the above embodiments, or may exist independently and not incorporated into the server. The storage medium carries one or more computer programs, which, when executed by a processor of the server, enable the server to implement the short link generation method provided in the above embodiments.
[0120] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0121] As used in the above embodiments, the term “when…” may be interpreted to mean “if…” or “after…” or “in response to determining…” or “in response to detecting…”, depending on the context. Similarly, the phrases “upon determining…” or “if (stated condition or event) is detected” may be interpreted to mean “if determining…” or “in response to determining…” or “upon detecting (stated condition or event)” or “in response to detecting (stated condition or event)”, depending on the context.
[0122] Those skilled in the art will appreciate that all or part of the process steps in the above-described method embodiments can be implemented by a computer program instructing the relevant hardware. The program can be stored in a computer-readable storage medium, and when executed, the program can include the process steps in the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A short link generation method, characterized in that: Applied to a server, the method includes: obtaining user information, current time, and original web page address; Inputting the original webpage address into a preset hash function to obtain a hash value of a first length; generating a pseudo-random number based on the user information and the current time; Input the pseudo-random number into a preset index calculation formula to obtain a valid index; Based on the valid index, selecting consecutive characters of a second length from the hash value as a hash short code, where the first length is greater than the second length; Performing a security review on the hash short code to ensure that the hash short code does not contain preset sensitive words, preset easily confused characters, and / or preset known vulnerabilities; If the result of the security review is safe, the hash short code is encoded according to the preset link generation parameters to obtain the final short link, and the preset link generation parameters are used to represent the structure and attributes of the short link generation; The preset index calculation formula is: Wherein, I represents the valid index, R represents the pseudo-random number, p represents a preset prime number, φ represents a preset golden section constant, and L represents the first length of the hash value. Indicates floor operation, mod indicates modulo operation; After the step of encoding the hash short code according to preset link generation parameters to obtain a final short link if the result of the security review is safe, the method further includes: calculating the information entropy of the final short link; when the information entropy is greater than or equal to the preset information entropy threshold, storing the final short link, the original web page address, the user information and the current time in a distributed database; when the information entropy is less than the preset information entropy threshold, processing the final short link according to a preset information enhancement algorithm to obtain an optimized short link.
2. The method according to claim 1, characterized in that The security review of the hash short code to ensure that the hash short code does not contain preset sensitive words, preset easily confused characters and / or preset known vulnerabilities specifically includes: Match the hash short code with the preset sensitive word library to determine whether the preset sensitive word exists; Checking whether the preset easily confused characters exist in the hash short code; Input the hash short code into a preset vulnerability identification model to determine whether the preset known vulnerability exists; If the hash short code does not contain the preset sensitive words, the preset easily confused characters and / or the preset known vulnerabilities, the result of the security review is safe; If the hash short code contains the preset sensitive words, the preset easily confused characters and / or the preset known vulnerabilities, the result of the security review is unsafe.
3. The method according to claim 1, characterized in that If the result of the security review is safe, the hash short code is encoded according to the preset link generation parameters to obtain the final short link, which specifically includes: Determine a domain name prefix and a path separator based on the preset link generation parameters; Concatenate the domain name prefix, the path separator and the hash short code in a preset order; URL encode the concatenated string; The encoded character string is combined with the preset protocol identifier to obtain the final short link.
4. The method according to claim 3, characterized in that After the step of performing a security review on the hash short code to ensure that the hash short code does not contain preset sensitive words, preset easily confused characters, and / or preset known vulnerabilities, the method further includes: If the result of the safety review is unsafe, determine the cause of the unsafety; Based on the insecurity reason, a corresponding correction strategy is selected from a preset correction strategy library; according to the correction strategy, the hash short code is corrected to obtain an optimized hash short code.
5. The method according to claim 1, wherein The calculating the information entropy of the final short link specifically includes: Counting the total number of characters in the final short link and the number of occurrences of each character; Divide the number of occurrences of each character by the total number of characters in the final short link to obtain the occurrence probability of each character; The occurrence probability of each character is input into a preset information entropy calculation formula to obtain the information entropy of the final short link. The preset information entropy calculation formula is: H=-∑[P(si)*log2(p(si))]; Wherein, H represents the information entropy, P(si) represents the occurrence probability of each character, and si represents each character.
6. A server, characterized in that: The server includes: one or more processors and a memory; the memory is coupled to the one or more processors, the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to cause the server to execute the method according to any one of claims 1 to 5.
7. A computer-readable storage medium comprising instructions, characterized in that: When the instructions are executed on a server, the server is caused to perform the method according to any one of claims 1 to 5.
8. A computer program product, characterized in that When the computer program product is run on a server, the server is caused to perform the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Short link generation method and device, electronic equipment and storage medium
CN116501997A