Skip to content

Commit 772b8e4

Browse files
authored
Merge pull request #219 from righettod/master
Add stats tab (fix error).
2 parents 43b3e0c + 02e34b1 commit 772b8e4

26 files changed

+129
-52
lines changed

.github/workflows/tab-stats-headers-generate-related-files.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: update_tab_stats_related_files
22
on:
33
workflow_dispatch:
44
schedule:
5-
- cron: '0 0 3 * *'
5+
- cron: '0 0 5 * *'
66
push:
77
paths:
88
- 'ci/tab_stats_generate_md_file.py'
@@ -15,15 +15,15 @@ jobs:
1515
contents: write
1616
steps:
1717
- uses: actions/checkout@v4
18-
- name: Set up Python 3.10
18+
- name: Set up Python
1919
uses: actions/setup-python@v5
2020
with:
2121
python-version: "3.10"
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
2525
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
26-
sudo apt install -y wget dos2unix
26+
sudo apt install -y wget dos2unix sqlite3
2727
- name: Run update of the tab related files
2828
run: |
2929
cd ci; bash tab_stats_manage_generation.sh
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

ci/tab_stats_generate_md_file.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99
"""
1010
import sqlite3
1111
import re
12-
import requests
12+
import json
1313
import hashlib
1414
from collections import Counter
1515
from datetime import datetime
1616
from pathlib import Path
1717

1818
# Constants
19-
HTTP_REQUEST_TIMEOUT = 60
19+
DEBUG = True
2020
DATA_DB_FILE = "/tmp/data.db"
21-
OSHP_SECURITY_HEADERS_FILE_lOCATION = "https://owasp.org/www-project-secure-headers/ci/headers_add.json"
21+
OSHP_SECURITY_HEADERS_FILE_lOCATION = "headers_add.json"
22+
OSHP_SECURITY_HEADERS_EXTRA_FILE_LOCATION = "/tmp/oshp_headers_extra_to_include.txt"
2223
MD_FILE = "../tab_statistics.md"
2324
IMAGE_FOLDER_LOCATION = "../assets/tab_stats_generated_images"
2425
TAB_MD_TEMPLATE = """---
@@ -55,31 +56,51 @@
5556
# Utility functions
5657

5758

59+
def trace(msg):
60+
if DEBUG:
61+
print(f"[DEBUG] {msg}")
62+
63+
5864
def prepare_generation_of_image_from_mermaid(mermaid_code, filename):
65+
trace(f"Call prepare_generation_of_image_from_mermaid() => {filename}")
5966
with open(f"{IMAGE_FOLDER_LOCATION}/{filename}.mmd", "w", encoding="utf-8") as f:
6067
f.write(mermaid_code + "\n")
68+
trace("Call end.")
6169

6270

6371
def load_oshp_headers():
72+
trace("Call load_oshp_headers()")
6473
header_names = []
65-
resp = requests.get(OSHP_SECURITY_HEADERS_FILE_lOCATION, timeout=HTTP_REQUEST_TIMEOUT)
66-
if resp.status_code != 200:
67-
raise Exception(f"Status code {resp.status_code} received!")
68-
for http_header in resp.json()["headers"]:
69-
header_names.append(http_header["name"])
74+
trace(f"Call load_oshp_headers() :: Load and parse file {OSHP_SECURITY_HEADERS_FILE_lOCATION}")
75+
with open(OSHP_SECURITY_HEADERS_FILE_lOCATION, mode="r", encoding="utf-8") as f:
76+
data = json.load(f)
77+
http_headers = data["headers"]
78+
for http_header in http_headers:
79+
header_names.append(http_header["name"].lower())
80+
trace(f"Call load_oshp_headers() :: Load file {OSHP_SECURITY_HEADERS_EXTRA_FILE_LOCATION}")
81+
with open(OSHP_SECURITY_HEADERS_EXTRA_FILE_LOCATION, mode="r", encoding="utf-8") as f:
82+
http_headers = f.read()
83+
trace(f"Call load_oshp_headers() :: Parse file {OSHP_SECURITY_HEADERS_EXTRA_FILE_LOCATION}")
84+
for http_header in http_headers .split("\n"):
85+
header_names.append(http_header.lower().strip(" \n\r\t"))
86+
header_names = list(dict.fromkeys(header_names))
7087
header_names.sort()
88+
trace("Call end.")
7189
return header_names
7290

7391

7492
def execute_query_against_data_db(sql_query):
93+
trace(f"Call execute_query_against_data_db() => {sql_query}")
7594
with sqlite3.connect(DATA_DB_FILE) as connection:
7695
curs = connection.cursor()
7796
curs.execute(sql_query)
7897
records = curs.fetchall()
98+
trace("Call end.")
7999
return records
80100

81101

82102
def add_stats_section(title, description, chart_mermaid_code):
103+
trace(f"Call add_stats_section() => '{title}'")
83104
with open(MD_FILE, mode="a", encoding="utf-8") as f:
84105
if chart_mermaid_code is not None and len(chart_mermaid_code.strip()) > 0:
85106
base_image_filename = hashlib.sha1(title.encode("utf8")).hexdigest()
@@ -88,14 +109,17 @@ def add_stats_section(title, description, chart_mermaid_code):
88109
else:
89110
md_code = SECTION_TEMPLATE_NO_MERMAID_CODE % (title, description)
90111
f.write(f"{md_code}\n")
112+
trace("Call end.")
91113

92114

93115
def init_stats_file():
116+
trace("Call init_stats_file()")
94117
with open(MD_FILE, mode="w", encoding="utf-8") as f:
95118
cdate = datetime.now().strftime("%m/%d/%Y at %H:%M:%S")
96119
f.write(TAB_MD_TEMPLATE)
97120
f.write("\n\n")
98121
f.write(f"⏲️ Last update: {cdate} - Domains analyzed count: {get_domains_count()}.\n")
122+
trace("Call end.")
99123

100124

101125
def get_domains_count():
@@ -248,8 +272,10 @@ def compute_csp_using_directives_with_unsafe_expressions_configuration_global_us
248272

249273

250274
if __name__ == "__main__":
275+
trace("Clear PNG files")
251276
for path in Path(IMAGE_FOLDER_LOCATION).glob("*.png"):
252277
path.unlink()
278+
trace("Clear MMD files")
253279
for path in Path(IMAGE_FOLDER_LOCATION).glob("*.mmd"):
254280
path.unlink()
255281
oshp_headers = load_oshp_headers()

ci/tab_stats_generate_png_files.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
#
55
# Dependencies:
66
# https://github.com/mermaid-js/mermaid-cli
7+
#
8+
# Reference:
9+
# https://github.com/mermaid-js/mermaid-cli/blob/master/.github/workflows/test.yml#L24
710
#########################################################################
811
# Constants
912
IMAGE_FOLDER_LOCATION="../assets/tab_stats_generated_images"
1013
# Generate images
14+
# We use aa-exec since Ubuntu 24.04's AppArmor profile blocks the use of puppeteer otherwise
15+
# See https://github.com/puppeteer/puppeteer/issues/12818
1116
cd $IMAGE_FOLDER_LOCATION
1217
for mmd_file in *.mmd
1318
do
1419
png_file="${mmd_file%%.*}.png"
15-
npx -p @mermaid-js/mermaid-cli mmdc --quiet --input $mmd_file --output $png_file --outputFormat png --theme default --backgroundColor transparent
20+
aa-exec --profile=chrome npx -p @mermaid-js/mermaid-cli mmdc --quiet --input $mmd_file --output $png_file --outputFormat png --theme default --backgroundColor transparent
1621
done
1722
# Only let PNG files
1823
rm *.mmd

ci/tab_stats_manage_generation.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,35 @@
33
# This script manage the generation/update of the tab represented by the
44
# file "tab_statistics.md".
55
#########################################################################
6+
OSHP_SECURITY_HEADERS_EXTRA_FILE_LOCATION="https://raw.githubusercontent.com/oshp/oshp-stats/refs/heads/main/scripts/oshp_headers_extra_to_include.txt"
7+
OSHP_SECURITY_HEADERS_EXTRA_FILE="/tmp/oshp_headers_extra_to_include.txt"
68
DATA_DB_FILE_LOCATION="https://github.com/oshp/oshp-stats/raw/refs/heads/main/data/data.db"
79
DATA_DB_FILE="/tmp/data.db"
8-
echo "[+] Download the database of headers analysis..."
10+
IMAGE_FOLDER_LOCATION="../assets/tab_stats_generated_images"
11+
echo "[+] Download the database of headers analysis anc validate the database file..."
912
wget -q -O $DATA_DB_FILE $DATA_DB_FILE_LOCATION
13+
wget -q -O $OSHP_SECURITY_HEADERS_EXTRA_FILE $OSHP_SECURITY_HEADERS_EXTRA_FILE_LOCATION
1014
file $DATA_DB_FILE
15+
sqlite3 $DATA_DB_FILE ".tables"
16+
file $OSHP_SECURITY_HEADERS_EXTRA_FILE
17+
wc -l $OSHP_SECURITY_HEADERS_EXTRA_FILE
1118
echo "[+] Set correct access rights for the scripts as well as UNIX CRLF settings..."
12-
dos2unix tab_stats_generate_*
19+
dos2unix *.sh
1320
chmod +x tab_stats_generate_*
1421
echo "[+] Generate the MD file of the TAB and all the MMD files for every pie chart image..."
1522
python tab_stats_generate_md_file.py
1623
echo "[+] Generate the PNG image corresponding to each MMD file..."
1724
bash tab_stats_generate_png_files.sh
1825
echo "[+] Cleanup"
19-
rm $DATA_DB_FILE
26+
rm $DATA_DB_FILE
27+
rm $OSHP_SECURITY_HEADERS_EXTRA_FILE
28+
echo "[+] Check correct generation of the images..."
29+
img_count=$(find $IMAGE_FOLDER_LOCATION -name "*.png" | wc -l)
30+
if [ $img_count -eq 0 ]
31+
then
32+
echo "[!] No image file was generated!"
33+
exit 1
34+
else
35+
echo "[V] $img_count image files were generated!"
36+
exit 0
37+
fi

tab_statistics.md

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ tags: headers
1717

1818

1919

20-
⏲️ Last update: 02/02/2025 at 15:29:30 - Domains analyzed count: 150000.
20+
⏲️ Last update: 02/02/2025 at 18:10:17 - Domains analyzed count: 150000.
2121

2222
## Global usage of secure headers
2323

@@ -26,88 +26,116 @@ Provide the distribution of usage of secure headers across all domains analyzed.
2626
![be611e71c615c27471d766612bfb7e8b05d743c7](assets/tab_stats_generated_images/be611e71c615c27471d766612bfb7e8b05d743c7.png)
2727

2828

29-
## Global usage of header 'Cache-Control'
29+
## Global usage of header 'cache-control'
3030

31-
Provide the distribution of usage of the header 'Cache-Control' across all domains analyzed.
31+
Provide the distribution of usage of the header 'cache-control' across all domains analyzed.
3232

33-
![5b54b09f5f5c815a014d71b3b07495a69e3a4509](assets/tab_stats_generated_images/5b54b09f5f5c815a014d71b3b07495a69e3a4509.png)
33+
![577d76c6092c4da6347e1d2c89523dd13a1925f7](assets/tab_stats_generated_images/577d76c6092c4da6347e1d2c89523dd13a1925f7.png)
3434

3535

36-
## Global usage of header 'Clear-Site-Data'
36+
## Global usage of header 'clear-site-data'
3737

38-
Provide the distribution of usage of the header 'Clear-Site-Data' across all domains analyzed.
38+
Provide the distribution of usage of the header 'clear-site-data' across all domains analyzed.
3939

40-
![2e12376a6c60ad301b25193c11517ea0cd6aba2f](assets/tab_stats_generated_images/2e12376a6c60ad301b25193c11517ea0cd6aba2f.png)
40+
![49f6a7d15e9a2e3fd4cad94360d37e83ef05fa00](assets/tab_stats_generated_images/49f6a7d15e9a2e3fd4cad94360d37e83ef05fa00.png)
4141

4242

43-
## Global usage of header 'Content-Security-Policy'
43+
## Global usage of header 'content-security-policy'
4444

45-
Provide the distribution of usage of the header 'Content-Security-Policy' across all domains analyzed.
45+
Provide the distribution of usage of the header 'content-security-policy' across all domains analyzed.
4646

47-
![5e74150e7d98f861bf3fa632ca32e2d7f3e59632](assets/tab_stats_generated_images/5e74150e7d98f861bf3fa632ca32e2d7f3e59632.png)
47+
![2da94599d03c73073ac60b0d8864152f8609cc5b](assets/tab_stats_generated_images/2da94599d03c73073ac60b0d8864152f8609cc5b.png)
4848

4949

50-
## Global usage of header 'Cross-Origin-Embedder-Policy'
50+
## Global usage of header 'content-security-policy-report-only'
5151

52-
Provide the distribution of usage of the header 'Cross-Origin-Embedder-Policy' across all domains analyzed.
52+
Provide the distribution of usage of the header 'content-security-policy-report-only' across all domains analyzed.
5353

54-
![00334f25a22543fb684dbe10861afee71c5263e0](assets/tab_stats_generated_images/00334f25a22543fb684dbe10861afee71c5263e0.png)
54+
![c0b5a705e7e94af3f71ef579bb01b45c2a80ca6b](assets/tab_stats_generated_images/c0b5a705e7e94af3f71ef579bb01b45c2a80ca6b.png)
5555

5656

57-
## Global usage of header 'Cross-Origin-Opener-Policy'
57+
## Global usage of header 'cross-origin-embedder-policy'
5858

59-
Provide the distribution of usage of the header 'Cross-Origin-Opener-Policy' across all domains analyzed.
59+
Provide the distribution of usage of the header 'cross-origin-embedder-policy' across all domains analyzed.
6060

61-
![f700c02d30083cf617bdeca51e7eec3d49fe4a08](assets/tab_stats_generated_images/f700c02d30083cf617bdeca51e7eec3d49fe4a08.png)
61+
![0753b0c4fecc8c56d81e31f36bc8c397cea5032b](assets/tab_stats_generated_images/0753b0c4fecc8c56d81e31f36bc8c397cea5032b.png)
6262

6363

64-
## Global usage of header 'Cross-Origin-Resource-Policy'
64+
## Global usage of header 'cross-origin-opener-policy'
6565

66-
Provide the distribution of usage of the header 'Cross-Origin-Resource-Policy' across all domains analyzed.
66+
Provide the distribution of usage of the header 'cross-origin-opener-policy' across all domains analyzed.
6767

68-
![fa069b07281496f391d957d8936337da1a601614](assets/tab_stats_generated_images/fa069b07281496f391d957d8936337da1a601614.png)
68+
![e7e550d9cbff786153f7f13f664361e41efee57c](assets/tab_stats_generated_images/e7e550d9cbff786153f7f13f664361e41efee57c.png)
6969

7070

71-
## Global usage of header 'Permissions-Policy'
71+
## Global usage of header 'cross-origin-resource-policy'
7272

73-
Provide the distribution of usage of the header 'Permissions-Policy' across all domains analyzed.
73+
Provide the distribution of usage of the header 'cross-origin-resource-policy' across all domains analyzed.
7474

75-
![0792b92709f42a7962c27c64b74b94a4dfbffda1](assets/tab_stats_generated_images/0792b92709f42a7962c27c64b74b94a4dfbffda1.png)
75+
![9cf15b18b743939cbe01342ed5461bc7af6c4d36](assets/tab_stats_generated_images/9cf15b18b743939cbe01342ed5461bc7af6c4d36.png)
7676

7777

78-
## Global usage of header 'Referrer-Policy'
78+
## Global usage of header 'expect-ct'
7979

80-
Provide the distribution of usage of the header 'Referrer-Policy' across all domains analyzed.
80+
Provide the distribution of usage of the header 'expect-ct' across all domains analyzed.
8181

82-
![d5e855464d800d7b27eb3e430c5ae378497ddf50](assets/tab_stats_generated_images/d5e855464d800d7b27eb3e430c5ae378497ddf50.png)
82+
![78fc7e8d03077546e27c016ee80b2143dc4ebb08](assets/tab_stats_generated_images/78fc7e8d03077546e27c016ee80b2143dc4ebb08.png)
8383

8484

85-
## Global usage of header 'Strict-Transport-Security'
85+
## Global usage of header 'permissions-policy'
8686

87-
Provide the distribution of usage of the header 'Strict-Transport-Security' across all domains analyzed.
87+
Provide the distribution of usage of the header 'permissions-policy' across all domains analyzed.
8888

89-
![dbeb94ebb1ed7763f390b7be97a292f3c66920c7](assets/tab_stats_generated_images/dbeb94ebb1ed7763f390b7be97a292f3c66920c7.png)
89+
![87eabe1fe075f9034dc4db8f76be07da0d08afe3](assets/tab_stats_generated_images/87eabe1fe075f9034dc4db8f76be07da0d08afe3.png)
9090

9191

92-
## Global usage of header 'X-Content-Type-Options'
92+
## Global usage of header 'public-key-pins'
9393

94-
Provide the distribution of usage of the header 'X-Content-Type-Options' across all domains analyzed.
94+
Provide the distribution of usage of the header 'public-key-pins' across all domains analyzed.
9595

96-
![0259a15512c639e10df724dc019babf03534b303](assets/tab_stats_generated_images/0259a15512c639e10df724dc019babf03534b303.png)
96+
![e58d592c018472a09777c3fd5440f556bd176dd5](assets/tab_stats_generated_images/e58d592c018472a09777c3fd5440f556bd176dd5.png)
9797

9898

99-
## Global usage of header 'X-Frame-Options'
99+
## Global usage of header 'referrer-policy'
100100

101-
Provide the distribution of usage of the header 'X-Frame-Options' across all domains analyzed.
101+
Provide the distribution of usage of the header 'referrer-policy' across all domains analyzed.
102102

103-
![6ddd8e89eb34224bf460f672999c7dd447baef79](assets/tab_stats_generated_images/6ddd8e89eb34224bf460f672999c7dd447baef79.png)
103+
![15d82f7cac9021b254fdf8fed98bb870acc436fb](assets/tab_stats_generated_images/15d82f7cac9021b254fdf8fed98bb870acc436fb.png)
104104

105105

106-
## Global usage of header 'X-Permitted-Cross-Domain-Policies'
106+
## Global usage of header 'strict-transport-security'
107107

108-
Provide the distribution of usage of the header 'X-Permitted-Cross-Domain-Policies' across all domains analyzed.
108+
Provide the distribution of usage of the header 'strict-transport-security' across all domains analyzed.
109109

110-
![364a633adcd63d315ec3df781fed6008c57ad00d](assets/tab_stats_generated_images/364a633adcd63d315ec3df781fed6008c57ad00d.png)
110+
![c313c0ceef6eb3116547426b41bdf278df2cc0c6](assets/tab_stats_generated_images/c313c0ceef6eb3116547426b41bdf278df2cc0c6.png)
111+
112+
113+
## Global usage of header 'x-content-type-options'
114+
115+
Provide the distribution of usage of the header 'x-content-type-options' across all domains analyzed.
116+
117+
![5808d16f90388bd6309eb12d74010d1c4a8518cf](assets/tab_stats_generated_images/5808d16f90388bd6309eb12d74010d1c4a8518cf.png)
118+
119+
120+
## Global usage of header 'x-frame-options'
121+
122+
Provide the distribution of usage of the header 'x-frame-options' across all domains analyzed.
123+
124+
![cfaf56ab8ec6588aa6ee9297b4f93638640d1048](assets/tab_stats_generated_images/cfaf56ab8ec6588aa6ee9297b4f93638640d1048.png)
125+
126+
127+
## Global usage of header 'x-permitted-cross-domain-policies'
128+
129+
Provide the distribution of usage of the header 'x-permitted-cross-domain-policies' across all domains analyzed.
130+
131+
![2ec5e9a684938a169c757a7a631595c53fccc769](assets/tab_stats_generated_images/2ec5e9a684938a169c757a7a631595c53fccc769.png)
132+
133+
134+
## Global usage of header 'x-xss-protection'
135+
136+
Provide the distribution of usage of the header 'x-xss-protection' across all domains analyzed.
137+
138+
![7b2906800d5eb94d25d0f5cf18322155e8f2192d](assets/tab_stats_generated_images/7b2906800d5eb94d25d0f5cf18322155e8f2192d.png)
111139

112140

113141
## Global usage of insecure framing configuration via the header 'x-frame-options'

0 commit comments

Comments
 (0)