-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava
More file actions
64 lines (61 loc) · 2.03 KB
/
Java
File metadata and controls
64 lines (61 loc) · 2.03 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
// Replace with your actual Google Safe Browsing API key
const API_KEY = "YOUR_GOOGLE_SAFE_BROWSING_API_KEY";
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "checkUrl") {
const urlToCheck = request.url;
fetch("https://safebrowsing.googleapis.com/v4/threatMatches:find?key=" + API_KEY, {
method: "POST",
body: JSON.stringify({
client: {
clientId: "beaconsafe-extension",
clientVersion: "2.0"
},
threatInfo: {
threatTypes: ["MALWARE", "SOCIAL_ENGINEERING", "UNWANTED_SOFTWARE", "POTENTIALLY_HARMFUL_APPLICATION"],
platformTypes: ["ANY_PLATFORM"],
threatEntryTypes: ["URL"],
threatEntries: [
{ url: urlToCheck }
]
}
}),
headers: {
"Content-Type": "application/json"
}
})
.then(response => response.json())
.then(data => {
if (data && data.matches) {
sendResponse({ unsafe: true });
} else {
sendResponse({ unsafe: false });
}
})
.catch(error => {
console.error("Safe Browsing API error:", error);
sendResponse({ unsafe: false });
});
// Indicate async response
return true;
}
});
3. content.js
JavaScript
// Only check top-level frame
if (window.top === window.self) {
chrome.runtime.sendMessage(
{ action: "checkUrl", url: window.location.href },
(response) => {
if (response && response.unsafe) {
document.body.innerHTML = `
<div style="background: #b30000; color: #fff; height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;">
<h1 style="font-size:3em;">⛔ BEACONSAFE ALERT</h1>
<p style="font-size:1.5em;">This webpage is flagged as unsafe and may try to hack you!</p>
<p style="font-size:1.2em;">We recommend closing this page immediately.</p>
</div>
`;
document.title = "⚠️ Unsafe Webpage Blocked";
}
}
);
}