Skip to content

Commit c140fe1

Browse files
author
drighetto
committed
Add monitoring script
1 parent 3781c2f commit c140fe1

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: perform_monitoring_oshp_site_references
2+
on:
3+
workflow_dispatch:
4+
push:
5+
paths:
6+
- 'tab_casestudies.md'
7+
schedule:
8+
- cron: '0 0 * * 0'
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python 3.10
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: "3.10"
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
22+
- name: Run the validation
23+
run: |
24+
cd ci; python monitoring_oshp_site_references.py
25+
26+

ci/monitoring_oshp_site_references.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
Utility script to verify that every site mentioned in the tab named "Case Studies" have a mention to OSHP.
3+
4+
The goal is to allow detection of site not mentioning the OSHP anymore and then update the "Case Studies" content.
5+
6+
Try to not use any external dependency to stay the more portable possible.
7+
"""
8+
import re
9+
import urllib.request
10+
11+
OSHP_MARKER_STRINGS = ["owasp secure headers project", "https://owasp.org/www-project-secure-headers", "https://www.owasp.org/index.php/security_headers", "secure headers project"]
12+
DEFAULT_ENCODING = "utf-8"
13+
IGNORED_HTTP_RESPONSE_CODES = [401]
14+
SOURCE_MD_FILE = "../tab_casestudies.md"
15+
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
16+
17+
18+
def verify_mention(site_url):
19+
oshp_is_mentioned = "NO"
20+
request = urllib.request.Request(url=site_url, method="GET")
21+
request.add_header("User-Agent", USER_AGENT)
22+
request.add_header("Accept", "*/*")
23+
request.add_header("Accept-Encoding", "deflate")
24+
try:
25+
# Assume by default that site refer to static non SPA page
26+
with urllib.request.urlopen(request) as f:
27+
content = f.read().decode(DEFAULT_ENCODING)
28+
content_lower = content.lower()
29+
for marker in OSHP_MARKER_STRINGS:
30+
if marker in content_lower:
31+
oshp_is_mentioned = "YES"
32+
break
33+
# If mention is not detected then try to check if it's an SPA
34+
if oshp_is_mentioned == "NO":
35+
expr = r'app\.[a-f0-9]+\.js'
36+
bundles = re.findall(expr, content)
37+
if len(bundles) > 0 or "React" in content:
38+
oshp_is_mentioned = "NO => SPA"
39+
except urllib.error.HTTPError as e:
40+
if e.code in IGNORED_HTTP_RESPONSE_CODES:
41+
oshp_is_mentioned = f"HTTP {e.code}"
42+
return oshp_is_mentioned
43+
44+
45+
def extract_site_urls():
46+
expr = r'\*\s+\[[a-zA-Z0-9\s_\-\.]+\]\((.*?)\)'
47+
with open(SOURCE_MD_FILE, mode="r", encoding=DEFAULT_ENCODING) as f:
48+
content = f.read()
49+
return re.findall(expr, content)
50+
51+
52+
if __name__ == "__main__":
53+
verify_mention("https://eoahgl4pezvrojk.m.pipedream.net/")
54+
print("[+] Extract site urls...")
55+
site_urls = extract_site_urls()
56+
print(f"{len(site_urls)} urls founds.")
57+
print("[+] Verify mention to OSHP on each site...")
58+
lines = []
59+
for site_url in site_urls:
60+
if site_url.strip().startswith("http"):
61+
oshp_is_mentioned = verify_mention(site_url)
62+
lines.append(f"[{str(oshp_is_mentioned):<9}] {site_url}")
63+
lines.sort()
64+
print("\n".join(lines))

tab_casestudies.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ https://owasp.org/www-project-secure-headers/index.html#div-technical_php
4444

4545
* [Cloud.gov](https://cloud.gov/docs/management/headers/).
4646
* [Amazon AWS](https://docs.aws.amazon.com/whitepapers/latest/secure-content-delivery-amazon-cloudfront/improving-security-by-enabling-security-specific-headers.html).
47-
* [Salesforce](https://documentation.b2c.commercecloud.salesforce.com/DOC1/topic/com.demandware.dochelp/content/b2c_commerce/topics/b2c_security_best_practices/b2c_declarative_security_via_http_headers.html?resultof=%22%68%65%61%64%65%72%73%22%20%22%68%65%61%64%65%72%22%20).
47+
* [Salesforce](https://help.salesforce.com/s/articleView?language=en_US&id=cc.b2c_declarative_security_via_http_headers.htm&type=5).
4848
* [Black Hills Information Security](https://www.blackhillsinfosec.com/fixing-content-security-policies-with-cloudflare-workers/).
4949
* [Progress](https://www.progress.com/documentation/sitefinity-cms/110/predefined-security-headers-in-http-response).
5050
* [Bloomreach](https://documentation.bloomreach.com/14/library/concepts/security/configure-security-response-headers.html).
51-
* [CrashTest Security](https://crashtest-security.com/enable-security-headers/).
5251
* [Tableau](https://help.tableau.com/current/server-linux/en-us/security_http_headers.htm).
5352
* [42Crunch](https://docs.42crunch.com/latest/content/extras/protection_security_headers.htm).
5453
* [SAP](https://help.sap.com/docs/SAP_UPSCALE_COMMERCE/4620dd88ff9047c89ffb7fa897207a46/30af09ca9e394505a85661fa530d1263.html).

0 commit comments

Comments
 (0)