-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpopup.js
More file actions
executable file
·449 lines (367 loc) · 13.5 KB
/
popup.js
File metadata and controls
executable file
·449 lines (367 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/**
* debugHunter v2.0.1 - Popup Script
* Features: Diff viewer, Severity stats, Scan status
*/
// ============================================================================
// MESSAGING
// ============================================================================
async function sendMessage(action, data = {}) {
return new Promise((resolve) => {
chrome.runtime.sendMessage({ action, ...data }, (response) => {
resolve(response || { params: [], headers: [], paths: [] });
});
});
}
async function getFindings() {
return await sendMessage('getFindings');
}
async function removeFinding(type, identifier) {
return await sendMessage('removeFinding', { type, identifier });
}
async function clearFindings(type = null) {
return await sendMessage(type ? 'clearFindings' : 'clearAll', { type });
}
async function getScanStatus() {
return await sendMessage('getScanStatus');
}
async function getEnabled() {
return await sendMessage('getEnabled');
}
async function setEnabled(enabled) {
return await sendMessage('setEnabled', { enabled });
}
// ============================================================================
// SEVERITY STATS
// ============================================================================
function updateSeverityStats(findings) {
const allFindings = [
...(findings.params || []),
...(findings.headers || []),
...(findings.paths || [])
];
const counts = { critical: 0, high: 0, medium: 0, low: 0 };
allFindings.forEach(f => {
if (f.severity && counts.hasOwnProperty(f.severity)) {
counts[f.severity]++;
}
});
document.getElementById('stat-critical').textContent = counts.critical;
document.getElementById('stat-high').textContent = counts.high;
document.getElementById('stat-medium').textContent = counts.medium;
document.getElementById('stat-low').textContent = counts.low;
}
// ============================================================================
// SCAN STATUS
// ============================================================================
function updateScanStatusUI(status) {
const statusBar = document.getElementById('status-bar');
const statusDomain = document.getElementById('status-domain');
if (status && status.active) {
statusBar.classList.add('active');
statusDomain.textContent = status.domain || 'unknown';
} else {
statusBar.classList.remove('active');
}
}
// Listen for scan status updates
chrome.runtime.onMessage.addListener((message) => {
if (message.action === 'scanStatus') {
updateScanStatusUI(message.status);
}
});
// ============================================================================
// SEARCH / FILTER
// ============================================================================
let currentSearchTerm = '';
function filterFindings(searchTerm) {
currentSearchTerm = searchTerm.toLowerCase().trim();
const clearBtn = document.getElementById('search-clear');
const resultsInfo = document.getElementById('search-results-info');
const searchCount = document.getElementById('search-count');
// Show/hide clear button
clearBtn.classList.toggle('visible', currentSearchTerm.length > 0);
// Get all finding items
const allItems = document.querySelectorAll('.finding-item');
let visibleCount = 0;
allItems.forEach(item => {
if (!currentSearchTerm) {
item.classList.remove('hidden');
visibleCount++;
} else {
// Search in URL, path, header, param, and other data attributes
const url = item.querySelector('.finding-url');
const meta = item.querySelector('.finding-meta');
const searchText = [
url?.textContent || '',
url?.title || '',
meta?.textContent || ''
].join(' ').toLowerCase();
const matches = searchText.includes(currentSearchTerm);
item.classList.toggle('hidden', !matches);
if (matches) visibleCount++;
}
});
// Show results info
if (currentSearchTerm) {
resultsInfo.classList.add('visible');
searchCount.textContent = visibleCount;
} else {
resultsInfo.classList.remove('visible');
}
// Update category counts to show filtered counts
['paths', 'headers', 'params'].forEach(type => {
const list = document.getElementById(`${type}-list`);
if (list) {
const visibleInCategory = list.querySelectorAll('.finding-item:not(.hidden)').length;
const countEl = document.getElementById(`${type}-count`);
if (countEl && currentSearchTerm) {
countEl.textContent = visibleInCategory;
}
}
});
}
function clearSearch() {
const searchInput = document.getElementById('search-input');
searchInput.value = '';
filterFindings('');
updateUI(); // Restore original counts
}
// ============================================================================
// DIFF VIEWER
// ============================================================================
let currentDiffData = null;
function showDiffModal(finding, type) {
const modal = document.getElementById('diff-modal');
const title = document.getElementById('modal-title');
const originalContent = document.getElementById('diff-original');
const modifiedContent = document.getElementById('diff-modified');
currentDiffData = finding;
// Set title based on type
if (type === 'paths') {
title.textContent = `Content: ${finding.path}`;
} else if (type === 'headers') {
title.textContent = `Diff: ${finding.header}`;
} else {
title.textContent = `Diff: ${finding.param}`;
}
// Set content (paths don't have originalResponse since they're different URLs)
if (type === 'paths') {
originalContent.textContent = '(Sensitive path found - no comparison needed)';
modifiedContent.textContent = finding.modifiedResponse || 'No response stored';
} else {
originalContent.textContent = finding.originalResponse || 'No original response stored';
modifiedContent.textContent = finding.modifiedResponse || 'No modified response stored';
}
modal.classList.add('active');
}
function hideDiffModal() {
const modal = document.getElementById('diff-modal');
modal.classList.remove('active');
currentDiffData = null;
}
// ============================================================================
// UI RENDERING
// ============================================================================
function truncateUrl(url, maxLength = 55) {
if (!url) return '';
if (url.length <= maxLength) return url;
return url.substring(0, maxLength - 3) + '...';
}
function createFindingItem(data, type, identifier) {
const item = document.createElement('div');
item.className = 'finding-item';
// Severity bar
const severityBar = document.createElement('div');
severityBar.className = `finding-severity ${data.severity || 'medium'}`;
item.appendChild(severityBar);
// Content
const content = document.createElement('div');
content.className = 'finding-content';
// URL link
const urlLink = document.createElement('a');
urlLink.className = 'finding-url';
urlLink.target = '_blank';
if (type === 'paths') {
urlLink.href = data.path;
urlLink.textContent = truncateUrl(data.path);
urlLink.title = data.path;
} else if (type === 'headers') {
urlLink.href = data.url;
urlLink.textContent = truncateUrl(`${data.url}`);
urlLink.title = `${data.url}\nHeader: ${data.header}`;
} else {
urlLink.href = data.url;
urlLink.textContent = truncateUrl(data.url);
urlLink.title = `${data.url}\nParam: ${data.param}`;
}
content.appendChild(urlLink);
// Meta info
const meta = document.createElement('div');
meta.className = 'finding-meta';
// Severity tag
if (data.severity) {
const severityTag = document.createElement('span');
severityTag.className = `finding-tag ${data.severity}`;
severityTag.textContent = data.severity.toUpperCase();
meta.appendChild(severityTag);
}
// Additional info
const info = document.createElement('span');
info.className = 'finding-info';
if (type === 'params' && data.param) {
info.textContent = data.param;
} else if (type === 'headers' && data.header) {
info.textContent = data.header;
} else if (type === 'paths' && data.contentLength) {
info.textContent = `${data.contentLength} bytes`;
}
if (info.textContent) {
meta.appendChild(info);
}
content.appendChild(meta);
item.appendChild(content);
// Actions
const actions = document.createElement('div');
actions.className = 'finding-actions';
// View button (diff for params/headers, content for paths)
if (data.originalResponse || data.modifiedResponse) {
const viewBtn = document.createElement('button');
viewBtn.className = 'action-btn diff';
viewBtn.title = type === 'paths' ? 'View Content' : 'View Diff';
viewBtn.innerHTML = type === 'paths' ? '<i class="fas fa-eye"></i>' : '<i class="fas fa-columns"></i>';
viewBtn.onclick = (e) => {
e.stopPropagation();
showDiffModal(data, type);
};
actions.appendChild(viewBtn);
}
// Remove button
const removeBtn = document.createElement('button');
removeBtn.className = 'action-btn remove';
removeBtn.title = 'Remove';
removeBtn.innerHTML = '<i class="fas fa-times"></i>';
removeBtn.onclick = async (e) => {
e.stopPropagation();
await removeFinding(type, identifier);
updateUI();
};
actions.appendChild(removeBtn);
item.appendChild(actions);
return item;
}
function updateCount(type, count) {
const countEl = document.getElementById(`${type}-count`);
if (countEl) {
countEl.textContent = count.toString();
countEl.classList.toggle('has-items', count > 0);
}
}
function renderList(type, items) {
const list = document.getElementById(`${type}-list`);
if (!list) return;
list.innerHTML = '';
if (!items || items.length === 0) {
const empty = document.createElement('div');
empty.className = 'empty-state';
empty.innerHTML = '<i class="fas fa-check-circle"></i>No findings yet';
list.appendChild(empty);
return;
}
items.forEach((item) => {
let identifier;
if (type === 'paths') {
identifier = item.path;
} else if (type === 'headers') {
identifier = `${item.url}|${item.header}`;
} else {
identifier = item.url;
}
const itemEl = createFindingItem(item, type, identifier);
list.appendChild(itemEl);
});
}
async function updateUI() {
const findings = await getFindings();
renderList('paths', findings.paths || []);
renderList('headers', findings.headers || []);
renderList('params', findings.params || []);
updateCount('paths', (findings.paths || []).length);
updateCount('headers', (findings.headers || []).length);
updateCount('params', (findings.params || []).length);
updateSeverityStats(findings);
// Update scan status
const status = await getScanStatus();
updateScanStatusUI(status);
// Reapply search filter if active
if (currentSearchTerm) {
filterFindings(currentSearchTerm);
}
}
// ============================================================================
// EVENT HANDLERS
// ============================================================================
document.addEventListener('DOMContentLoaded', async () => {
updateUI();
// Initialize scan toggle state
const scanToggle = document.getElementById('scan-toggle');
const enabledState = await getEnabled();
scanToggle.checked = enabledState.enabled;
// Scan toggle handler
scanToggle.addEventListener('change', async (e) => {
await setEnabled(e.target.checked);
});
// Category collapse toggle
document.querySelectorAll('.category-header').forEach((header) => {
header.addEventListener('click', () => {
header.parentElement.classList.toggle('collapsed');
});
});
// Options link
document.getElementById('options-link').addEventListener('click', (e) => {
e.preventDefault();
chrome.runtime.openOptionsPage();
});
// GitHub info link
document.getElementById('info-icon').addEventListener('click', (e) => {
e.preventDefault();
chrome.tabs.create({ url: 'https://github.com/devploit/debugHunter' });
});
// Clear all button
document.getElementById('clear-all').addEventListener('click', async (e) => {
e.preventDefault();
await clearFindings();
updateUI();
});
// Modal close button
document.getElementById('modal-close').addEventListener('click', hideDiffModal);
// Close modal on overlay click
document.getElementById('diff-modal').addEventListener('click', (e) => {
if (e.target.id === 'diff-modal') {
hideDiffModal();
}
});
// Close modal on Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
hideDiffModal();
}
});
// Search functionality
const searchInput = document.getElementById('search-input');
const searchClear = document.getElementById('search-clear');
searchInput.addEventListener('input', (e) => {
filterFindings(e.target.value);
});
searchClear.addEventListener('click', () => {
clearSearch();
});
// Clear search on Escape when focused
searchInput.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
clearSearch();
searchInput.blur();
}
});
});
// Refresh UI periodically to catch new findings
setInterval(updateUI, 5000);