11// List of query parameters to append
22const queryParams = [
33 { key : "_debug" , value : "1" } ,
4- { key : "test" , value : "1" } ,
54 { key : "admin" , value : "1" } ,
6- { key : "debug" , value : "1" } ,
7- { key : "env" , value : "pre" } ,
8- { key : "dev" , value : "1" } ,
9- { key : "staging" , value : "1" } ,
5+ { key : "analysis" , value : "1" } ,
6+ { key : "beta" , value : "1" } ,
107 { key : "console" , value : "1" } ,
11- { key : "trace" , value : "1" } ,
12- { key : "log" , value : "1" } ,
13- { key : "verbose" , value : "1" } ,
14- { key : "diagnostic" , value : "1" } ,
15- { key : "mode" , value : "debug" } ,
16- { key : "profiler" , value : "1" } ,
8+ { key : "debug" , value : "1" } ,
9+ { key : "debug_flag" , value : "1" } ,
1710 { key : "debug_mode" , value : "1" } ,
11+ { key : "debug_output" , value : "1" } ,
12+ { key : "debug_status" , value : "1" } ,
13+ { key : "debuginfo" , value : "1" } ,
1814 { key : "debuglevel" , value : "1" } ,
15+ { key : "dev" , value : "1" } ,
16+ { key : "dev_mode" , value : "1" } ,
17+ { key : "development" , value : "1" } ,
18+ { key : "diagnostic" , value : "1" } ,
19+ { key : "env" , value : "pre" } ,
1920 { key : "error_reporting" , value : "1" } ,
20- { key : "show_errors" , value : "1" } ,
21+ { key : "experiment" , value : "1" } ,
22+ { key : "internal" , value : "1" } ,
23+ { key : "log" , value : "1" } ,
24+ { key : "mode" , value : "debug" } ,
25+ { key : "monitoring" , value : "1" } ,
2126 { key : "performance" , value : "1" } ,
22- { key : "sandbox" , value : "1" } ,
23- { key : "beta" , value : "1" } ,
27+ { key : "profiler" , value : "1" } ,
2428 { key : "qa" , value : "1" } ,
25- { key : "dev_mode " , value : "1" } ,
26- { key : "validate " , value : "1" } ,
27- { key : "analysis " , value : "1" } ,
28- { key : "experiment " , value : "1" } ,
29+ { key : "sandbox " , value : "1" } ,
30+ { key : "show_errors " , value : "1" } ,
31+ { key : "staging " , value : "1" } ,
32+ { key : "test " , value : "1" } ,
2933 { key : "test_mode" , value : "1" } ,
30- { key : "debug_flag" , value : "1" } ,
31- { key : "development" , value : "1" } ,
32- { key : "debuginfo" , value : "1" } ,
33- { key : "monitoring" , value : "1" } ,
34- { key : "internal" , value : "1" } ,
35- { key : "debug_status" , value : "1" } ,
36- { key : "debug_output" , value : "1" } ,
3734 { key : "testing" , value : "1" } ,
35+ { key : "trace" , value : "1" } ,
36+ { key : "validate" , value : "1" } ,
37+ { key : "verbose" , value : "1" } ,
3838] ;
3939
4040// Counter for the number of modified URLs
@@ -93,97 +93,76 @@ function clearModifiedUrls() {
9393window . getModifiedUrls = getModifiedUrls ;
9494window . clearModifiedUrls = clearModifiedUrls ;
9595
96+ // Preprocess Text from responses
97+ function preprocessText ( text ) {
98+ return text . replace ( / \s + / g, '' ) ;
99+ }
100+
96101// Function to check if two responses are meaningfully different
97102function isDifferentResponse ( originalText , modifiedText ) {
98- // Calculate the similarity between the two responses
99- const similarity = stringSimilarity . compareTwoStrings ( originalText , modifiedText ) ;
103+ // Preprocess the texts before comparison
104+ const preprocessedOriginalText = preprocessText ( originalText ) ;
105+ const preprocessedModifiedText = preprocessText ( modifiedText ) ;
106+
107+ // Calculate the similarity between the two preprocessed responses
108+ const similarity = stringSimilarity . compareTwoStrings (
109+ preprocessedOriginalText ,
110+ preprocessedModifiedText
111+ ) ;
100112
101113 // Set a threshold for similarity; responses with similarity below this threshold are considered different
102- const similarityThreshold = 0.90 ;
114+ const similarityThreshold = 0.93 ;
103115
104116 // Return true if the similarity is below the threshold
105117 return similarity < similarityThreshold ;
106118}
107119
108- // Function to fetch URL and compare responses with and without each parameter
109- async function checkUrlWithParameters ( url , parameters ) {
110- const originalResponse = await fetch ( url ) ;
111- const originalText = await originalResponse . text ( ) ;
112-
113- // Check the response with all parameters combined
114- const combinedUrl = parameters . reduce ( ( currentUrl , param ) => {
115- return appendQueryParam ( currentUrl , param ) ;
116- } , url ) ;
117- const combinedResponse = await fetch ( combinedUrl ) ;
118- const combinedText = await combinedResponse . text ( ) ;
119-
120- if ( ! isDifferentResponse ( originalText , combinedText ) ) {
121- // If the response is the same, there is no need to perform the binary search
120+ // Perform the binary search
121+ async function binarySearch ( url , includedParams , searchParams , originalText ) {
122+ if ( searchParams . length === 0 ) {
122123 return ;
123124 }
124125
125- // Define the start and end indices for the binary search
126- let startIndex = 0 ;
127- let endIndex = parameters . length - 1 ;
128-
129- // Perform the binary search
130- while ( startIndex <= endIndex ) {
131- // Calculate the middle index
132- const middleIndex = Math . floor ( ( startIndex + endIndex ) / 2 ) ;
133-
134- // Construct the modified URL using the parameters up to the middle index
135- const modifiedUrl = parameters . slice ( 0 , middleIndex + 1 ) . reduce ( ( currentUrl , param ) => {
136- return appendQueryParam ( currentUrl , param ) ;
137- } , url ) ;
138-
139- // Fetch the modified response and compare it to the original response
126+ if ( searchParams . length === 1 ) {
127+ const modifiedUrl = appendQueryParam ( url , searchParams [ 0 ] ) ;
140128 const modifiedResponse = await fetch ( modifiedUrl ) ;
141129 const modifiedText = await modifiedResponse . text ( ) ;
142-
143130 if ( isDifferentResponse ( originalText , modifiedText ) ) {
144- // If the response is different, add the modified URL and search for more modifications
145131 addModifiedUrl ( modifiedUrl ) ;
146- endIndex = middleIndex - 1 ;
147- } else {
148- // If the response is the same, continue searching in the upper half of the list
149- startIndex = middleIndex + 1 ;
150132 }
133+ return ;
151134 }
152135
153- // Check each parameter individually until the first parameter that modifies the response is found
154- let found = false ;
155- for ( const param of parameters ) {
156- const modifiedUrl = appendQueryParam ( url , param ) ;
157- const modifiedResponse = await fetch ( modifiedUrl ) ;
158- const modifiedText = await modifiedResponse . text ( ) ;
136+ // Calculate the middle index
137+ const middleIndex = Math . floor ( searchParams . length / 2 ) ;
159138
160- if ( isDifferentResponse ( originalText , modifiedText ) ) {
161- // If the response is different, add the modified URL to the set
162- addModifiedUrl ( modifiedUrl ) ;
163- found = true ;
164- break ;
165- }
166- }
139+ // Construct the modified URL using the includedParams and up to the middle index of searchParams
140+ const modifiedUrl = includedParams . concat ( searchParams . slice ( 0 , middleIndex ) ) . reduce ( ( currentUrl , param ) => {
141+ return appendQueryParam ( currentUrl , param ) ;
142+ } , url ) ;
167143
168- // If there are only two parameters left and we have a modified response when using only one of them,
169- // try the other parameter
170- if ( ! found && parameters . length === 2 ) {
171- const modifiedUrl = appendQueryParam ( url , parameters [ 0 ] ) ;
172- const modifiedResponse = await fetch ( modifiedUrl ) ;
173- const modifiedText = await modifiedResponse . text ( ) ;
144+ // Fetch the modified response and compare it to the original response
145+ const modifiedResponse = await fetch ( modifiedUrl ) ;
146+ const modifiedText = await modifiedResponse . text ( ) ;
147+
148+ if ( isDifferentResponse ( originalText , modifiedText ) ) {
149+ // If the response is different, add the modified URL and search for more modifications
150+ addModifiedUrl ( modifiedUrl ) ;
151+ await binarySearch ( url , includedParams , searchParams . slice ( 0 , middleIndex ) , originalText ) ;
152+ } else {
153+ // If the response is the same, continue searching in the upper half of the list
154+ await binarySearch ( url , includedParams . concat ( searchParams . slice ( 0 , middleIndex ) ) , searchParams . slice ( middleIndex ) , originalText ) ;
155+ }
156+ }
174157
175- if ( ! isDifferentResponse ( originalText , modifiedText ) ) {
176- const otherModifiedUrl = appendQueryParam ( url , parameters [ 1 ] ) ;
177- const otherModifiedResponse = await fetch ( otherModifiedUrl ) ;
178- const otherModifiedText = await otherModifiedResponse . text ( ) ;
158+ // Function to check URL with parameters
159+ async function checkUrlWithParameters ( url , parameters ) {
160+ // Fetch the original response only once
161+ const originalResponse = await fetch ( url ) ;
162+ const originalText = await originalResponse . text ( ) ;
179163
180- if ( isDifferentResponse ( originalText , otherModifiedText ) ) {
181- addModifiedUrl ( otherModifiedUrl ) ;
182- }
183- } else {
184- addModifiedUrl ( modifiedUrl ) ;
185- }
186- }
164+ // Perform the binary search with the full list of parameters and the original response text
165+ await binarySearch ( url , [ ] , parameters , originalText ) ;
187166}
188167
189168// Listen for tab updates to perform background checks
@@ -195,4 +174,4 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
195174
196175// Expose getModifiedUrls and clearModifiedUrls functions to popup
197176window . getModifiedUrls = getModifiedUrls ;
198- window . clearModifiedUrls = clearModifiedUrls ;
177+ window . clearModifiedUrls = clearModifiedUrls ;
0 commit comments