Skip to content

Commit a121eb4

Browse files
committed
feat: implement Content Security Policy and update dependencies in HTML template
1 parent 7244ced commit a121eb4

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
app = Flask(__name__)
1111
CORS(app) # Enable CORS for all routes
1212

13+
CSP_POLICY = (
14+
"default-src 'self'; "
15+
"script-src 'self' 'unsafe-inline' https://tools-static.wmflabs.org; "
16+
"style-src 'self' 'unsafe-inline' https://tools-static.wmflabs.org; "
17+
"connect-src 'self' https://api.github.com; "
18+
"img-src 'self' data:; "
19+
"font-src 'self' https://tools-static.wmflabs.org data:"
20+
)
21+
22+
@app.after_request
23+
def set_security_headers(response):
24+
response.headers['Content-Security-Policy'] = CSP_POLICY
25+
return response
26+
1327
behaviour_switches = ['__NOTOC__', '__FORCETOC__', '__TOC__', '__NOEDITSECTION__', '__NEWSECTIONLINK__', '__NONEWSECTIONLINK__', '__NOGALLERY__', '__HIDDENCAT__', '__EXPECTUNUSEDCATEGORY__', '__NOCONTENTCONVERT__', '__NOCC__', '__NOTITLECONVERT__', '__NOTC__', '__START__', '__END__', '__INDEX__', '__NOINDEX__', '__STATICREDIRECT__', '__EXPECTUNUSEDTEMPLATE__', '__NOGLOBAL__', '__DISAMBIG__', '__EXPECTED_UNCONNECTED_PAGE__', '__ARCHIVEDTALK__', '__NOTALK__', '__EXPECTWITHOUTSCANS__']
1428

1529
# --- Helper Functions for Processing Different Wikitext Elements ---

templates/home.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<title>Wikitext to Translatable Wikitext Converter</title>
77
<link
88
rel="stylesheet"
9-
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/css/bootstrap.min.css"
9+
href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/bootstrap/5.3.8/css/bootstrap.min.css"
1010
/>
1111

1212
<link
1313
rel="stylesheet"
14-
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-light.min.css"
14+
href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/highlight.js/11.11.1/styles/atom-one-light.min.css"
1515
/>
1616
<style>
1717
html,
@@ -140,8 +140,8 @@ <h5>Translatable Wikitext Output</h5>
140140
</div>
141141

142142
<!-- Bootstrap JS and dependencies -->
143-
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/js/bootstrap.bundle.min.js"></script>
144-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
143+
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/bootstrap/5.3.8/js/bootstrap.bundle.min.js"></script>
144+
<script src="https://tools-static.wmflabs.org/cdnjs/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
145145
<script>
146146
hljs.highlightAll();
147147

0 commit comments

Comments
 (0)