File tree Expand file tree Collapse file tree 3 files changed +159
-0
lines changed
Expand file tree Collapse file tree 3 files changed +159
-0
lines changed Original file line number Diff line number Diff line change 1+ from flask import Flask , render_template , request
2+ import requests
3+
4+ app = Flask (__name__ )
5+
6+ SECURITY_HEADERS = [
7+ "X-Frame-Options" ,
8+ "X-XSS-Protection" ,
9+ "Content-Security-Policy" ,
10+ "Strict-Transport-Security"
11+ ]
12+
13+ @app .route ("/" , methods = ["GET" , "POST" ])
14+ def index ():
15+ result = None
16+
17+ if request .method == "POST" :
18+ url = request .form .get ("url" )
19+
20+ # Add http if user forgets
21+ if not url .startswith ("http://" ) and not url .startswith ("https://" ):
22+ url = "http://" + url
23+
24+ try :
25+ response = requests .get (url , timeout = 5 )
26+ headers = response .headers
27+
28+ missing_headers = []
29+ for header in SECURITY_HEADERS :
30+ if header not in headers :
31+ missing_headers .append (header )
32+
33+ https_status = url .startswith ("https://" )
34+
35+ result = {
36+ "url" : url ,
37+ "https" : https_status ,
38+ "missing_headers" : missing_headers
39+ }
40+
41+ except requests .exceptions .RequestException :
42+ result = {
43+ "error" : "Unable to connect to the website"
44+ }
45+
46+ return render_template ("index.html" , result = result )
47+
48+ if __name__ == "__main__" :
49+ app .run (debug = True )
Original file line number Diff line number Diff line change 1+ flask
2+ requests
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+
4+ < head >
5+ < title > HTTPS & Security Header Checker</ title >
6+ < style >
7+ body {
8+ font-family : Arial, sans-serif;
9+ background : # f4f6f8 ;
10+ padding : 40px ;
11+ }
12+
13+ .container {
14+ max-width : 600px ;
15+ margin : auto;
16+ background : white;
17+ padding : 25px ;
18+ border-radius : 8px ;
19+ box-shadow : 0px 0px 10px rgba (0 , 0 , 0 , 0.1 );
20+ }
21+
22+ h1 {
23+ text-align : center;
24+ }
25+
26+ input [type = text ] {
27+ width : 100% ;
28+ padding : 10px ;
29+ margin-top : 10px ;
30+ }
31+
32+ button {
33+ margin-top : 15px ;
34+ padding : 10px ;
35+ width : 100% ;
36+ background : # 007bff ;
37+ color : white;
38+ border : none;
39+ cursor : pointer;
40+ }
41+
42+ button : hover {
43+ background : # 0056b3 ;
44+ }
45+
46+ .result {
47+ margin-top : 20px ;
48+ padding : 15px ;
49+ background : # f1f1f1 ;
50+ }
51+
52+ .secure {
53+ color : green;
54+ font-weight : bold;
55+ }
56+
57+ .not-secure {
58+ color : red;
59+ font-weight : bold;
60+ }
61+
62+ ul {
63+ padding-left : 20px ;
64+ }
65+ </ style >
66+ </ head >
67+
68+ < body >
69+
70+ < div class ="container ">
71+ < h1 > HTTPS & Security Header Checker</ h1 >
72+
73+ < form method ="POST ">
74+ < label > Enter Website URL:</ label >
75+ < input type ="text " name ="url " placeholder ="example.com " required >
76+ < button type ="submit "> Check Security</ button >
77+ </ form >
78+
79+ {% if result %}
80+ < div class ="result ">
81+ {% if result.error %}
82+ < p class ="not-secure "> {{ result.error }}</ p >
83+ {% else %}
84+ < p > < strong > Website:</ strong > {{ result.url }}</ p >
85+
86+ < p >
87+ < strong > HTTPS Status:</ strong > {% if result.https %}
88+ < span class ="secure "> Secure (HTTPS)</ span > {% else %}
89+ < span class ="not-secure "> Not Secure (HTTP)</ span > {% endif %}
90+ </ p >
91+
92+ < p > < strong > Missing Security Headers:</ strong > </ p >
93+ {% if result.missing_headers %}
94+ < ul >
95+ {% for header in result.missing_headers %}
96+ < li > {{ header }}</ li >
97+ {% endfor %}
98+ </ ul >
99+ {% else %}
100+ < p class ="secure "> All important security headers are present</ p >
101+ {% endif %} {% endif %}
102+ </ div >
103+ {% endif %}
104+ </ div >
105+
106+ </ body >
107+
108+ </ html >
You can’t perform that action at this time.
0 commit comments