Update app.py
Browse files
app.py
CHANGED
@@ -41,16 +41,15 @@ AD_CONFIG = {
|
|
41 |
}
|
42 |
""",
|
43 |
'js': """
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
// Clean existing elements
|
49 |
blockedElements.forEach(selector => {
|
50 |
document.querySelectorAll(selector).forEach(el => el.remove());
|
51 |
});
|
52 |
|
53 |
-
//
|
54 |
new MutationObserver(mutations => {
|
55 |
mutations.forEach(({ addedNodes }) => {
|
56 |
addedNodes.forEach(node => {
|
@@ -61,20 +60,11 @@ AD_CONFIG = {
|
|
61 |
}
|
62 |
});
|
63 |
});
|
64 |
-
}).observe(document.body, {
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
if(blockedPatterns.some(pattern => new RegExp(pattern, 'i').test(url))) {
|
70 |
-
return new Promise(() => {});
|
71 |
-
}
|
72 |
-
return originalFetch(url, options);
|
73 |
-
};
|
74 |
-
}
|
75 |
-
|
76 |
-
document.addEventListener('DOMContentLoaded', nuclearCleaner);
|
77 |
-
window.addEventListener('load', nuclearCleaner);
|
78 |
"""
|
79 |
}
|
80 |
}
|
@@ -93,16 +83,14 @@ def enhance_security(html):
|
|
93 |
for element in soup.select(selector):
|
94 |
element.decompose()
|
95 |
|
96 |
-
# Iniezione
|
97 |
style = soup.new_tag('style')
|
98 |
style.string = AD_CONFIG['security']['css']
|
99 |
soup.head.append(style)
|
100 |
|
|
|
101 |
script = soup.new_tag('script')
|
102 |
-
script.string = AD_CONFIG['security']['js'] %
|
103 |
-
AD_CONFIG['blocked_patterns']['scripts'],
|
104 |
-
AD_CONFIG['blocked_patterns']['elements']
|
105 |
-
)
|
106 |
soup.body.append(script)
|
107 |
|
108 |
return str(soup)
|
@@ -130,16 +118,13 @@ def secure_proxy(path):
|
|
130 |
content_type=response.headers.get('Content-Type', 'text/html'),
|
131 |
headers={
|
132 |
'Cache-Control': 'no-store, max-age=0',
|
133 |
-
'X-Content-Type-Options': 'nosniff'
|
134 |
-
'X-Frame-Options': 'DENY'
|
135 |
}
|
136 |
)
|
137 |
return Response("Error: Origin server response", status=502)
|
138 |
|
139 |
-
except requests.exceptions.RequestException as e:
|
140 |
-
return Response(f"Network Error: {str(e)}", status=503)
|
141 |
except Exception as e:
|
142 |
-
return Response(f"
|
143 |
|
144 |
if __name__ == '__main__':
|
145 |
app.run()
|
|
|
41 |
}
|
42 |
""",
|
43 |
'js': """
|
44 |
+
document.addEventListener('DOMContentLoaded', () => {
|
45 |
+
const blockedElements = %s;
|
46 |
+
|
47 |
+
// Pulizia iniziale
|
|
|
48 |
blockedElements.forEach(selector => {
|
49 |
document.querySelectorAll(selector).forEach(el => el.remove());
|
50 |
});
|
51 |
|
52 |
+
// Observer per contenuti dinamici
|
53 |
new MutationObserver(mutations => {
|
54 |
mutations.forEach(({ addedNodes }) => {
|
55 |
addedNodes.forEach(node => {
|
|
|
60 |
}
|
61 |
});
|
62 |
});
|
63 |
+
}).observe(document.body, {
|
64 |
+
childList: true,
|
65 |
+
subtree: true
|
66 |
+
});
|
67 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
"""
|
69 |
}
|
70 |
}
|
|
|
83 |
for element in soup.select(selector):
|
84 |
element.decompose()
|
85 |
|
86 |
+
# Iniezione CSS
|
87 |
style = soup.new_tag('style')
|
88 |
style.string = AD_CONFIG['security']['css']
|
89 |
soup.head.append(style)
|
90 |
|
91 |
+
# Iniezione JS
|
92 |
script = soup.new_tag('script')
|
93 |
+
script.string = AD_CONFIG['security']['js'] % AD_CONFIG['blocked_patterns']['elements']
|
|
|
|
|
|
|
94 |
soup.body.append(script)
|
95 |
|
96 |
return str(soup)
|
|
|
118 |
content_type=response.headers.get('Content-Type', 'text/html'),
|
119 |
headers={
|
120 |
'Cache-Control': 'no-store, max-age=0',
|
121 |
+
'X-Content-Type-Options': 'nosniff'
|
|
|
122 |
}
|
123 |
)
|
124 |
return Response("Error: Origin server response", status=502)
|
125 |
|
|
|
|
|
126 |
except Exception as e:
|
127 |
+
return Response(f"Error: {str(e)}", status=500)
|
128 |
|
129 |
if __name__ == '__main__':
|
130 |
app.run()
|