ofershm commited on
Commit
06b92b5
1 Parent(s): bb73632

Create app

Browse files
Files changed (1) hide show
  1. app +61 -0
app ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup, Comment
3
+ import gradio as gr
4
+
5
+ def extract_comments_and_check_security(url):
6
+ results = {}
7
+
8
+ # Fetch and check the HTML comments
9
+ try:
10
+ response = requests.get(url)
11
+ results['Status Code'] = response.status_code
12
+
13
+ if response.status_code == 200:
14
+ soup = BeautifulSoup(response.text, 'html.parser')
15
+ comments = soup.find_all(string=True)
16
+ comment_list = [str(comment) for comment in comments if isinstance(comment, Comment)]
17
+ results['Comments'] = "\n\n".join(comment_list) if comment_list else "No comments found in the HTML."
18
+ else:
19
+ results['Comments'] = f"Failed to retrieve the webpage. Status code: {response.status_code}"
20
+ except Exception as e:
21
+ results['Comments'] = str(e)
22
+
23
+ # Check security headers
24
+ try:
25
+ security_headers = {}
26
+ headers = response.headers
27
+ security_headers['Strict-Transport-Security'] = headers.get('Strict-Transport-Security', 'Not Set')
28
+ security_headers['Content-Security-Policy'] = headers.get('Content-Security-Policy', 'Not Set')
29
+ security_headers['X-Content-Type-Options'] = headers.get('X-Content-Type-Options', 'Not Set')
30
+ security_headers['X-Frame-Options'] = headers.get('X-Frame-Options', 'Not Set')
31
+ security_headers['X-XSS-Protection'] = headers.get('X-XSS-Protection', 'Not Set')
32
+ results['Security Headers'] = security_headers
33
+ except Exception as e:
34
+ results['Security Headers'] = str(e)
35
+
36
+ # Check cookies for HttpOnly and SameSite attributes
37
+ try:
38
+ cookies = response.cookies
39
+ cookie_info = {}
40
+ for cookie in cookies:
41
+ cookie_info[cookie.name] = {
42
+ 'HttpOnly': cookie._rest.get('HttpOnly', 'Not Set'),
43
+ 'SameSite': cookie._rest.get('SameSite', 'Not Set')
44
+ }
45
+ results['Cookies'] = cookie_info if cookie_info else "No cookies found."
46
+ except Exception as e:
47
+ results['Cookies'] = str(e)
48
+
49
+ return results
50
+
51
+ # Create a Gradio interface
52
+ iface = gr.Interface(
53
+ fn=extract_comments_and_check_security,
54
+ inputs=gr.Textbox(label="Enter URL"),
55
+ outputs=gr.JSON(),
56
+ title="HTML Comment and Security Checker",
57
+ description="Enter a URL to extract comments from its HTML content and check for security headers and cookie attributes."
58
+ )
59
+
60
+ # Launch the Gradio app
61
+ iface.launch()