-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
63 lines (56 loc) · 2.1 KB
/
Copy pathcontent.js
File metadata and controls
63 lines (56 loc) · 2.1 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
// content.js - Injected into the active page to scan for vulnerabilities
// Function to check if a string looks like a JWT
function isJWT(token) {
const parts = token.split('.');
if (parts.length !== 3) return false;
try {
const header = JSON.parse(atob(parts[0]));
const payload = JSON.parse(atob(parts[1]));
return header && payload && header.alg;
} catch (e) {
return false;
}
}
// Function to scan storage for sensitive info
function scanStorage(storage, storageName) {
const findings = [];
for (let i = 0; i < storage.length; i++) {
const key = storage.key(i);
const value = storage.getItem(key);
// Check for JWTs
if (isJWT(value)) {
findings.push({ key, value, issue: 'JWT found in ' + storageName + ' (Vulnerable to XSS)' });
}
// Check for obvious unencrypted sensitive data keywords
const lowerKey = key.toLowerCase();
if (lowerKey.includes('password') || lowerKey.includes('secret') || lowerKey.includes('token') || lowerKey.includes('auth')) {
// Only flag if it doesn't look like a properly encrypted or hashed value (simple heuristic)
if (value.length < 100 && !value.startsWith('enc_') && !isJWT(value)) {
findings.push({ key, value, issue: 'Potential unencrypted sensitive data in ' + storageName });
}
}
}
return findings;
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "scanVulnerabilities") {
const localScan = scanStorage(localStorage, 'localStorage');
const sessionScan = scanStorage(sessionStorage, 'sessionStorage');
const cookieString = document.cookie;
// Check document.cookie exposure (Cookies accessible via JS)
const accessibleCookies = [];
if (cookieString) {
cookieString.split(';').forEach(c => {
accessibleCookies.push({
cookie: c.trim(),
issue: 'Cookie accessible via document.cookie (Missing HttpOnly flag)'
});
});
}
sendResponse({
localStorage: localScan,
sessionStorage: sessionScan,
documentCookies: accessibleCookies
});
}
});