-
Notifications
You must be signed in to change notification settings - Fork 326
Expand file tree
/
Copy pathsecurity.py
More file actions
72 lines (62 loc) · 1.72 KB
/
Copy pathsecurity.py
File metadata and controls
72 lines (62 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
import warnings
# Safe options allowed in HTML meta tags when parsing untrusted markup.
# Anything not in this allowlist is considered unsafe/untrusted and will be ignored
# unless 'allow_unsafe_meta_tags' is explicitly enabled.
ALLOWED_META_OPTIONS = frozenset([
# Page size & orientation
'page-size',
'page-width',
'page-height',
'orientation',
# Margins
'margin-top',
'margin-right',
'margin-bottom',
'margin-left',
# Document properties
'encoding',
'dpi',
'grayscale',
'lowquality',
'image-dpi',
'image-quality',
'title',
'no-pdf-compression',
'quiet',
# Header options (pure text / formatting, no file or URL loading)
'header-line',
'header-spacing',
'header-center',
'header-left',
'header-right',
'header-font-name',
'header-font-size',
# Footer options (pure text / formatting, no file or URL loading)
'footer-line',
'footer-spacing',
'footer-center',
'footer-left',
'footer-right',
'footer-font-name',
'footer-font-size',
# Outline options
'outline',
'outline-depth',
'no-outline',
# TOC formatting options
'toc-header-text',
'toc-level-indentation',
'toc-text-size-shrink',
])
def is_safe_meta_option(option_name):
"""
Checks if an option is present in the ALLOWED_META_OPTIONS allowlist.
Normalizes option names by stripping any leading dashes and lowercasing.
:param option_name: The name of the option to check.
:return: True if the option is safe, False otherwise.
"""
if not option_name:
return False
normalized = option_name.lower().lstrip('-')
return normalized in ALLOWED_META_OPTIONS