httpx-secure 1.2.0__tar.gz → 1.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- httpx_secure-1.3.0/.gitignore +454 -0
- {httpx_secure-1.2.0 → httpx_secure-1.3.0}/PKG-INFO +4 -8
- {httpx_secure-1.2.0 → httpx_secure-1.3.0}/README.md +1 -3
- {httpx_secure-1.2.0 → httpx_secure-1.3.0}/httpx_secure/__init__.py +29 -21
- {httpx_secure-1.2.0 → httpx_secure-1.3.0}/pyproject.toml +22 -50
- {httpx_secure-1.2.0 → httpx_secure-1.3.0}/tests/conftest.py +2 -2
- {httpx_secure-1.2.0 → httpx_secure-1.3.0}/tests/test___init__.py +71 -45
- httpx_secure-1.2.0/.editorconfig +0 -16
- httpx_secure-1.2.0/.envrc +0 -3
- httpx_secure-1.2.0/.github/workflows/workflow.yaml +0 -99
- httpx_secure-1.2.0/.gitignore +0 -183
- httpx_secure-1.2.0/.vscode/settings.json +0 -3
- httpx_secure-1.2.0/LICENSE +0 -12
- httpx_secure-1.2.0/shell.nix +0 -76
- httpx_secure-1.2.0/uv.lock +0 -254
- {httpx_secure-1.2.0 → httpx_secure-1.3.0}/httpx_secure/py.typed +0 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
|
|
2
|
+
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,c,cmake,direnv,dotenv,node,python,rust
|
|
3
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,linux,c,cmake,direnv,dotenv,node,python,rust
|
|
4
|
+
|
|
5
|
+
### C ###
|
|
6
|
+
# Prerequisites
|
|
7
|
+
*.d
|
|
8
|
+
|
|
9
|
+
# Object files
|
|
10
|
+
*.o
|
|
11
|
+
*.ko
|
|
12
|
+
*.obj
|
|
13
|
+
*.elf
|
|
14
|
+
|
|
15
|
+
# Linker output
|
|
16
|
+
*.ilk
|
|
17
|
+
*.map
|
|
18
|
+
*.exp
|
|
19
|
+
|
|
20
|
+
# Precompiled Headers
|
|
21
|
+
*.gch
|
|
22
|
+
*.pch
|
|
23
|
+
|
|
24
|
+
# Libraries
|
|
25
|
+
*.lib
|
|
26
|
+
*.a
|
|
27
|
+
*.la
|
|
28
|
+
*.lo
|
|
29
|
+
|
|
30
|
+
# Shared objects (inc. Windows DLLs)
|
|
31
|
+
*.dll
|
|
32
|
+
*.so
|
|
33
|
+
*.so.*
|
|
34
|
+
*.dylib
|
|
35
|
+
|
|
36
|
+
# Executables
|
|
37
|
+
*.exe
|
|
38
|
+
*.out
|
|
39
|
+
*.app
|
|
40
|
+
*.i*86
|
|
41
|
+
*.x86_64
|
|
42
|
+
*.hex
|
|
43
|
+
|
|
44
|
+
# Debug files
|
|
45
|
+
*.dSYM/
|
|
46
|
+
*.su
|
|
47
|
+
*.idb
|
|
48
|
+
*.pdb
|
|
49
|
+
|
|
50
|
+
# Kernel Module Compile Results
|
|
51
|
+
*.mod*
|
|
52
|
+
*.cmd
|
|
53
|
+
.tmp_versions/
|
|
54
|
+
modules.order
|
|
55
|
+
Module.symvers
|
|
56
|
+
Mkfile.old
|
|
57
|
+
dkms.conf
|
|
58
|
+
|
|
59
|
+
### CMake ###
|
|
60
|
+
CMakeLists.txt.user
|
|
61
|
+
CMakeCache.txt
|
|
62
|
+
CMakeFiles
|
|
63
|
+
CMakeScripts
|
|
64
|
+
Testing
|
|
65
|
+
Makefile
|
|
66
|
+
cmake_install.cmake
|
|
67
|
+
install_manifest.txt
|
|
68
|
+
compile_commands.json
|
|
69
|
+
CTestTestfile.cmake
|
|
70
|
+
_deps
|
|
71
|
+
|
|
72
|
+
### CMake Patch ###
|
|
73
|
+
CMakeUserPresets.json
|
|
74
|
+
|
|
75
|
+
# External projects
|
|
76
|
+
*-prefix/
|
|
77
|
+
|
|
78
|
+
### direnv ###
|
|
79
|
+
.direnv
|
|
80
|
+
.envrc
|
|
81
|
+
|
|
82
|
+
### dotenv ###
|
|
83
|
+
.env
|
|
84
|
+
|
|
85
|
+
### Linux ###
|
|
86
|
+
*~
|
|
87
|
+
|
|
88
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
|
89
|
+
.fuse_hidden*
|
|
90
|
+
|
|
91
|
+
# KDE directory preferences
|
|
92
|
+
.directory
|
|
93
|
+
|
|
94
|
+
# Linux trash folder which might appear on any partition or disk
|
|
95
|
+
.Trash-*
|
|
96
|
+
|
|
97
|
+
# .nfs files are created when an open file is removed but is still being accessed
|
|
98
|
+
.nfs*
|
|
99
|
+
|
|
100
|
+
### Node ###
|
|
101
|
+
# Logs
|
|
102
|
+
logs
|
|
103
|
+
*.log
|
|
104
|
+
npm-debug.log*
|
|
105
|
+
yarn-debug.log*
|
|
106
|
+
yarn-error.log*
|
|
107
|
+
lerna-debug.log*
|
|
108
|
+
.pnpm-debug.log*
|
|
109
|
+
|
|
110
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
111
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
112
|
+
|
|
113
|
+
# Runtime data
|
|
114
|
+
pids
|
|
115
|
+
*.pid
|
|
116
|
+
*.seed
|
|
117
|
+
*.pid.lock
|
|
118
|
+
|
|
119
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
120
|
+
lib-cov
|
|
121
|
+
|
|
122
|
+
# Coverage directory used by tools like istanbul
|
|
123
|
+
coverage
|
|
124
|
+
*.lcov
|
|
125
|
+
|
|
126
|
+
# nyc test coverage
|
|
127
|
+
.nyc_output
|
|
128
|
+
|
|
129
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
130
|
+
.grunt
|
|
131
|
+
|
|
132
|
+
# Bower dependency directory (https://bower.io/)
|
|
133
|
+
bower_components
|
|
134
|
+
|
|
135
|
+
# node-waf configuration
|
|
136
|
+
.lock-wscript
|
|
137
|
+
|
|
138
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
139
|
+
build/Release
|
|
140
|
+
|
|
141
|
+
# Dependency directories
|
|
142
|
+
node_modules/
|
|
143
|
+
jspm_packages/
|
|
144
|
+
|
|
145
|
+
# Snowpack dependency directory (https://snowpack.dev/)
|
|
146
|
+
web_modules/
|
|
147
|
+
|
|
148
|
+
# TypeScript cache
|
|
149
|
+
*.tsbuildinfo
|
|
150
|
+
|
|
151
|
+
# Optional npm cache directory
|
|
152
|
+
.npm
|
|
153
|
+
|
|
154
|
+
# Optional eslint cache
|
|
155
|
+
.eslintcache
|
|
156
|
+
|
|
157
|
+
# Optional stylelint cache
|
|
158
|
+
.stylelintcache
|
|
159
|
+
|
|
160
|
+
# Microbundle cache
|
|
161
|
+
.rpt2_cache/
|
|
162
|
+
.rts2_cache_cjs/
|
|
163
|
+
.rts2_cache_es/
|
|
164
|
+
.rts2_cache_umd/
|
|
165
|
+
|
|
166
|
+
# Optional REPL history
|
|
167
|
+
.node_repl_history
|
|
168
|
+
|
|
169
|
+
# Output of 'npm pack'
|
|
170
|
+
*.tgz
|
|
171
|
+
|
|
172
|
+
# Yarn Integrity file
|
|
173
|
+
.yarn-integrity
|
|
174
|
+
|
|
175
|
+
# dotenv environment variable files
|
|
176
|
+
.env.development.local
|
|
177
|
+
.env.test.local
|
|
178
|
+
.env.production.local
|
|
179
|
+
.env.local
|
|
180
|
+
|
|
181
|
+
# parcel-bundler cache (https://parceljs.org/)
|
|
182
|
+
.cache
|
|
183
|
+
.parcel-cache
|
|
184
|
+
|
|
185
|
+
# Next.js build output
|
|
186
|
+
.next
|
|
187
|
+
out
|
|
188
|
+
|
|
189
|
+
# Nuxt.js build / generate output
|
|
190
|
+
.nuxt
|
|
191
|
+
dist
|
|
192
|
+
|
|
193
|
+
# Gatsby files
|
|
194
|
+
.cache/
|
|
195
|
+
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
196
|
+
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
197
|
+
# public
|
|
198
|
+
|
|
199
|
+
# vuepress build output
|
|
200
|
+
.vuepress/dist
|
|
201
|
+
|
|
202
|
+
# vuepress v2.x temp and cache directory
|
|
203
|
+
.temp
|
|
204
|
+
|
|
205
|
+
# Docusaurus cache and generated files
|
|
206
|
+
.docusaurus
|
|
207
|
+
|
|
208
|
+
# Serverless directories
|
|
209
|
+
.serverless/
|
|
210
|
+
|
|
211
|
+
# FuseBox cache
|
|
212
|
+
.fusebox/
|
|
213
|
+
|
|
214
|
+
# DynamoDB Local files
|
|
215
|
+
.dynamodb/
|
|
216
|
+
|
|
217
|
+
# TernJS port file
|
|
218
|
+
.tern-port
|
|
219
|
+
|
|
220
|
+
# Stores VSCode versions used for testing VSCode extensions
|
|
221
|
+
.vscode-test
|
|
222
|
+
|
|
223
|
+
# yarn v2
|
|
224
|
+
.yarn/cache
|
|
225
|
+
.yarn/unplugged
|
|
226
|
+
.yarn/build-state.yml
|
|
227
|
+
.yarn/install-state.gz
|
|
228
|
+
.pnp.*
|
|
229
|
+
|
|
230
|
+
### Node Patch ###
|
|
231
|
+
# Serverless Webpack directories
|
|
232
|
+
.webpack/
|
|
233
|
+
|
|
234
|
+
# Optional stylelint cache
|
|
235
|
+
|
|
236
|
+
# SvelteKit build / generate output
|
|
237
|
+
.svelte-kit
|
|
238
|
+
|
|
239
|
+
### Python ###
|
|
240
|
+
# Byte-compiled / optimized / DLL files
|
|
241
|
+
__pycache__/
|
|
242
|
+
*.py[cod]
|
|
243
|
+
*$py.class
|
|
244
|
+
|
|
245
|
+
# C extensions
|
|
246
|
+
|
|
247
|
+
# Distribution / packaging
|
|
248
|
+
.Python
|
|
249
|
+
build/
|
|
250
|
+
develop-eggs/
|
|
251
|
+
dist/
|
|
252
|
+
downloads/
|
|
253
|
+
eggs/
|
|
254
|
+
.eggs/
|
|
255
|
+
lib/
|
|
256
|
+
lib64/
|
|
257
|
+
parts/
|
|
258
|
+
sdist/
|
|
259
|
+
var/
|
|
260
|
+
wheels/
|
|
261
|
+
share/python-wheels/
|
|
262
|
+
*.egg-info/
|
|
263
|
+
.installed.cfg
|
|
264
|
+
*.egg
|
|
265
|
+
MANIFEST
|
|
266
|
+
|
|
267
|
+
# PyInstaller
|
|
268
|
+
# Usually these files are written by a python script from a template
|
|
269
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
270
|
+
*.manifest
|
|
271
|
+
*.spec
|
|
272
|
+
|
|
273
|
+
# Installer logs
|
|
274
|
+
pip-log.txt
|
|
275
|
+
pip-delete-this-directory.txt
|
|
276
|
+
|
|
277
|
+
# Unit test / coverage reports
|
|
278
|
+
htmlcov/
|
|
279
|
+
.tox/
|
|
280
|
+
.nox/
|
|
281
|
+
.coverage
|
|
282
|
+
.coverage.*
|
|
283
|
+
nosetests.xml
|
|
284
|
+
coverage.xml
|
|
285
|
+
*.cover
|
|
286
|
+
*.py,cover
|
|
287
|
+
.hypothesis/
|
|
288
|
+
.pytest_cache/
|
|
289
|
+
cover/
|
|
290
|
+
|
|
291
|
+
# Translations
|
|
292
|
+
*.mo
|
|
293
|
+
*.pot
|
|
294
|
+
|
|
295
|
+
# Django stuff:
|
|
296
|
+
local_settings.py
|
|
297
|
+
db.sqlite3
|
|
298
|
+
db.sqlite3-journal
|
|
299
|
+
|
|
300
|
+
# Flask stuff:
|
|
301
|
+
instance/
|
|
302
|
+
.webassets-cache
|
|
303
|
+
|
|
304
|
+
# Scrapy stuff:
|
|
305
|
+
.scrapy
|
|
306
|
+
|
|
307
|
+
# Sphinx documentation
|
|
308
|
+
docs/_build/
|
|
309
|
+
|
|
310
|
+
# PyBuilder
|
|
311
|
+
.pybuilder/
|
|
312
|
+
target/
|
|
313
|
+
|
|
314
|
+
# Jupyter Notebook
|
|
315
|
+
.ipynb_checkpoints
|
|
316
|
+
|
|
317
|
+
# IPython
|
|
318
|
+
profile_default/
|
|
319
|
+
ipython_config.py
|
|
320
|
+
|
|
321
|
+
# pyenv
|
|
322
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
323
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
324
|
+
# .python-version
|
|
325
|
+
|
|
326
|
+
# pipenv
|
|
327
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
328
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
329
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
330
|
+
# install all needed dependencies.
|
|
331
|
+
#Pipfile.lock
|
|
332
|
+
|
|
333
|
+
# poetry
|
|
334
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
335
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
336
|
+
# commonly ignored for libraries.
|
|
337
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
338
|
+
#poetry.lock
|
|
339
|
+
|
|
340
|
+
# pdm
|
|
341
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
342
|
+
#pdm.lock
|
|
343
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
344
|
+
# in version control.
|
|
345
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
346
|
+
.pdm.toml
|
|
347
|
+
|
|
348
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
349
|
+
__pypackages__/
|
|
350
|
+
|
|
351
|
+
# Celery stuff
|
|
352
|
+
celerybeat-schedule
|
|
353
|
+
celerybeat.pid
|
|
354
|
+
|
|
355
|
+
# SageMath parsed files
|
|
356
|
+
*.sage.py
|
|
357
|
+
|
|
358
|
+
# Environments
|
|
359
|
+
.venv
|
|
360
|
+
env/
|
|
361
|
+
venv/
|
|
362
|
+
ENV/
|
|
363
|
+
env.bak/
|
|
364
|
+
venv.bak/
|
|
365
|
+
|
|
366
|
+
# Spyder project settings
|
|
367
|
+
.spyderproject
|
|
368
|
+
.spyproject
|
|
369
|
+
|
|
370
|
+
# Rope project settings
|
|
371
|
+
.ropeproject
|
|
372
|
+
|
|
373
|
+
# mkdocs documentation
|
|
374
|
+
/site
|
|
375
|
+
|
|
376
|
+
# mypy
|
|
377
|
+
.mypy_cache/
|
|
378
|
+
.dmypy.json
|
|
379
|
+
dmypy.json
|
|
380
|
+
|
|
381
|
+
# Pyre type checker
|
|
382
|
+
.pyre/
|
|
383
|
+
|
|
384
|
+
# pytype static type analyzer
|
|
385
|
+
.pytype/
|
|
386
|
+
|
|
387
|
+
# Cython debug symbols
|
|
388
|
+
cython_debug/
|
|
389
|
+
|
|
390
|
+
# PyCharm
|
|
391
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
392
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
393
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
394
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
395
|
+
#.idea/
|
|
396
|
+
|
|
397
|
+
### Python Patch ###
|
|
398
|
+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
|
399
|
+
poetry.toml
|
|
400
|
+
|
|
401
|
+
# ruff
|
|
402
|
+
.ruff_cache/
|
|
403
|
+
|
|
404
|
+
# LSP config files
|
|
405
|
+
pyrightconfig.json
|
|
406
|
+
|
|
407
|
+
### Rust ###
|
|
408
|
+
# Generated by Cargo
|
|
409
|
+
# will have compiled files and executables
|
|
410
|
+
debug/
|
|
411
|
+
|
|
412
|
+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
|
413
|
+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
|
414
|
+
Cargo.lock
|
|
415
|
+
|
|
416
|
+
# These are backup files generated by rustfmt
|
|
417
|
+
**/*.rs.bk
|
|
418
|
+
|
|
419
|
+
# MSVC Windows builds of rustc generate these, which store debugging information
|
|
420
|
+
|
|
421
|
+
### VisualStudioCode ###
|
|
422
|
+
.vscode/*
|
|
423
|
+
!.vscode/settings.json
|
|
424
|
+
!.vscode/tasks.json
|
|
425
|
+
!.vscode/launch.json
|
|
426
|
+
!.vscode/extensions.json
|
|
427
|
+
!.vscode/*.code-snippets
|
|
428
|
+
|
|
429
|
+
# Local History for Visual Studio Code
|
|
430
|
+
.history/
|
|
431
|
+
|
|
432
|
+
# Built Visual Studio Code Extensions
|
|
433
|
+
*.vsix
|
|
434
|
+
|
|
435
|
+
### VisualStudioCode Patch ###
|
|
436
|
+
# Ignore all local history of files
|
|
437
|
+
.history
|
|
438
|
+
.ionide
|
|
439
|
+
|
|
440
|
+
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,linux,c,cmake,direnv,dotenv,node,python,rust
|
|
441
|
+
|
|
442
|
+
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
|
|
443
|
+
|
|
444
|
+
!.envrc
|
|
445
|
+
|
|
446
|
+
.codex
|
|
447
|
+
repomix-output.xml
|
|
448
|
+
uv.lock
|
|
449
|
+
vendor/
|
|
450
|
+
|
|
451
|
+
githead/tests/git/HEAD
|
|
452
|
+
h2corn/bench/*.bin
|
|
453
|
+
h2corn/bench/results/*_summary.json
|
|
454
|
+
jinja2-htmlmin/tests/templates/.*
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httpx-secure
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: Drop-in SSRF protection for httpx
|
|
5
|
-
Project-URL:
|
|
6
|
-
Project-URL:
|
|
5
|
+
Project-URL: Issues, https://github.com/Zaczero/pkgs/issues
|
|
6
|
+
Project-URL: Repository, https://github.com/Zaczero/pkgs/tree/main/httpx-secure
|
|
7
7
|
Author-email: Kamil Monicz <kamil@monicz.dev>
|
|
8
8
|
License-Expression: 0BSD
|
|
9
|
-
License-File: LICENSE
|
|
10
9
|
Keywords: anyio,async,asyncio,client,dns,dns-cache,http,httpx,security,ssrf,ssrf-protection,trio,web-security
|
|
11
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
11
|
Classifier: Framework :: AnyIO
|
|
@@ -15,7 +14,6 @@ Classifier: Framework :: Trio
|
|
|
15
14
|
Classifier: Intended Audience :: Developers
|
|
16
15
|
Classifier: License :: OSI Approved :: Zero-Clause BSD (0BSD)
|
|
17
16
|
Classifier: Operating System :: OS Independent
|
|
18
|
-
Classifier: Programming Language :: Python :: 3
|
|
19
17
|
Classifier: Programming Language :: Python :: 3.9
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
19
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -36,8 +34,6 @@ Description-Content-Type: text/markdown
|
|
|
36
34
|
# httpx-secure
|
|
37
35
|
|
|
38
36
|
[](https://pypi.org/p/httpx-secure)
|
|
39
|
-
[](https://liberapay.com/Zaczero/)
|
|
40
|
-
[](https://github.com/sponsors/Zaczero)
|
|
41
37
|
|
|
42
38
|
Drop-in SSRF protection for httpx.
|
|
43
39
|
|
|
@@ -52,7 +48,7 @@ Drop-in SSRF protection for httpx.
|
|
|
52
48
|
|
|
53
49
|
## Installation
|
|
54
50
|
|
|
55
|
-
```
|
|
51
|
+
```sh
|
|
56
52
|
pip install httpx-secure
|
|
57
53
|
```
|
|
58
54
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# httpx-secure
|
|
2
2
|
|
|
3
3
|
[](https://pypi.org/p/httpx-secure)
|
|
4
|
-
[](https://liberapay.com/Zaczero/)
|
|
5
|
-
[](https://github.com/sponsors/Zaczero)
|
|
6
4
|
|
|
7
5
|
Drop-in SSRF protection for httpx.
|
|
8
6
|
|
|
@@ -17,7 +15,7 @@ Drop-in SSRF protection for httpx.
|
|
|
17
15
|
|
|
18
16
|
## Installation
|
|
19
17
|
|
|
20
|
-
```
|
|
18
|
+
```sh
|
|
21
19
|
pip install httpx-secure
|
|
22
20
|
```
|
|
23
21
|
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from collections import OrderedDict
|
|
4
4
|
from inspect import isawaitable
|
|
5
|
-
from ipaddress import ip_address
|
|
5
|
+
from ipaddress import IPv4Address, IPv6Address, IPv6Network, ip_address
|
|
6
6
|
from time import monotonic
|
|
7
7
|
from weakref import WeakValueDictionary
|
|
8
8
|
|
|
@@ -12,7 +12,6 @@ from httpx import ConnectError, ConnectTimeout, RequestError
|
|
|
12
12
|
TYPE_CHECKING = False
|
|
13
13
|
if TYPE_CHECKING:
|
|
14
14
|
from collections.abc import Awaitable, Callable
|
|
15
|
-
from ipaddress import IPv4Address, IPv6Address
|
|
16
15
|
from typing import TypeVar, Union
|
|
17
16
|
|
|
18
17
|
from httpx import AsyncClient, Request
|
|
@@ -21,9 +20,11 @@ if TYPE_CHECKING:
|
|
|
21
20
|
|
|
22
21
|
_CacheKey = tuple[str, int] # (hostname, port)
|
|
23
22
|
|
|
24
|
-
_AsyncClientT = TypeVar(
|
|
23
|
+
_AsyncClientT = TypeVar('_AsyncClientT', bound=AsyncClient)
|
|
25
24
|
|
|
26
|
-
__version__ =
|
|
25
|
+
__version__ = '1.3.0'
|
|
26
|
+
|
|
27
|
+
_NAT64_WELL_KNOWN_PREFIX = IPv6Network('64:ff9b::/96')
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
class SSRFProtectionError(RequestError):
|
|
@@ -45,7 +46,7 @@ class SSRFProtectionError(RequestError):
|
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
class _DNSCache:
|
|
48
|
-
__slots__ = (
|
|
49
|
+
__slots__ = ('_cache', '_max_size', '_ttl')
|
|
49
50
|
|
|
50
51
|
def __init__(self, max_size: int, ttl: float) -> None:
|
|
51
52
|
self._cache: OrderedDict[
|
|
@@ -92,12 +93,12 @@ class _DNSCache:
|
|
|
92
93
|
|
|
93
94
|
class _SSRFProtectionHook:
|
|
94
95
|
__slots__ = (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
'_cache',
|
|
97
|
+
'_locks',
|
|
98
|
+
'check_globally_reachable',
|
|
99
|
+
'connect_timeout',
|
|
100
|
+
'custom_validator',
|
|
101
|
+
'happy_eyeballs_delay',
|
|
101
102
|
)
|
|
102
103
|
|
|
103
104
|
def __init__(
|
|
@@ -146,15 +147,22 @@ class _SSRFProtectionHook:
|
|
|
146
147
|
ip_addr = ip_address(ip_str)
|
|
147
148
|
except ValueError as e:
|
|
148
149
|
raise SSRFProtectionError(
|
|
149
|
-
f
|
|
150
|
+
f'Invalid IP address format: {ip_str!r}',
|
|
150
151
|
hostname=hostname,
|
|
151
152
|
ip_addr=None,
|
|
152
153
|
port=port,
|
|
153
154
|
) from e
|
|
154
155
|
|
|
155
|
-
if self.check_globally_reachable and
|
|
156
|
+
if self.check_globally_reachable and (
|
|
157
|
+
not ip_addr.is_global
|
|
158
|
+
or (
|
|
159
|
+
isinstance(ip_addr, IPv6Address)
|
|
160
|
+
and ip_addr in _NAT64_WELL_KNOWN_PREFIX
|
|
161
|
+
and not IPv4Address(ip_addr.packed[-4:]).is_global
|
|
162
|
+
)
|
|
163
|
+
):
|
|
156
164
|
raise SSRFProtectionError(
|
|
157
|
-
f
|
|
165
|
+
f'Access denied: IP address {ip_str!r} is not globally reachable',
|
|
158
166
|
hostname=hostname,
|
|
159
167
|
ip_addr=ip_addr,
|
|
160
168
|
port=port,
|
|
@@ -166,7 +174,7 @@ class _SSRFProtectionHook:
|
|
|
166
174
|
result = await result
|
|
167
175
|
if not result:
|
|
168
176
|
raise SSRFProtectionError(
|
|
169
|
-
f
|
|
177
|
+
f'Access denied: IP address {ip_str!r} failed custom validation',
|
|
170
178
|
hostname=hostname,
|
|
171
179
|
ip_addr=ip_addr,
|
|
172
180
|
port=port,
|
|
@@ -210,13 +218,13 @@ class _SSRFProtectionHook:
|
|
|
210
218
|
async def __call__(self, request: Request) -> None:
|
|
211
219
|
url = request.url
|
|
212
220
|
hostname = url.host
|
|
213
|
-
port = url.port or (443 if url.scheme in {
|
|
221
|
+
port = url.port or (443 if url.scheme in {'https', 'wss'} else 80)
|
|
214
222
|
|
|
215
223
|
ip_str = await self._process(request, hostname, port)
|
|
216
224
|
|
|
217
225
|
request.url = url.copy_with(host=ip_str)
|
|
218
|
-
request.headers[
|
|
219
|
-
request.extensions[
|
|
226
|
+
request.headers['Host'] = hostname
|
|
227
|
+
request.extensions['sni_hostname'] = hostname
|
|
220
228
|
|
|
221
229
|
|
|
222
230
|
def httpx_ssrf_protection(
|
|
@@ -249,11 +257,11 @@ def httpx_ssrf_protection(
|
|
|
249
257
|
"""
|
|
250
258
|
if not check_globally_reachable and custom_validator is None:
|
|
251
259
|
raise ValueError(
|
|
252
|
-
|
|
253
|
-
|
|
260
|
+
'When check_globally_reachable is False, custom_validator must be provided '
|
|
261
|
+
'to ensure SSRF protection is not completely disabled',
|
|
254
262
|
)
|
|
255
263
|
|
|
256
|
-
client.event_hooks[
|
|
264
|
+
client.event_hooks['request'].append(
|
|
257
265
|
_SSRFProtectionHook(
|
|
258
266
|
cache=_DNSCache(dns_cache_size, dns_cache_ttl),
|
|
259
267
|
check_globally_reachable=check_globally_reachable,
|