A Python package to generate secure links for nginx.
Project description
📌 SecureLink
Expirable Signed URL Generator & API
SecureLink is a lightweight and flexible library for generating and verifying expirable signed URLs to control access to protected resources.
- 📦 Library Mode – Use it as a Python package to generate secure URLs.
- 🌍 API Mode – Deploy it as a FastAPI service to generate URLs via HTTP requests.
🚀 Features
- ✅ Expirable Links – Set expiration time for secure access
- ✅ Signed URLs – MD5
- ✅ FastAPI API – Built-in API for generating & verifying links
- ✅ Pluggable Architecture – Extendable for different signing strategies
- ✅ Works with Any Server – Supports Nginx etc.
📦 Installation
Library Mode:
pip install securelink
API Mode:
pip install securelink[api]
🔧 Environment Variables
-
SECRET_KEY: Used for signing and validating secure links.
-
API_KEY: Used for API authentication if needed.
📝 Example Scenarios
Library Mode:
import time
import securelink.sign
secure_url = securelink.sign.generate_md5_base64_url(
"http://127.0.0.1/secure/", "secret", 5, "127.0.0.1"
)
print("✅ Normal success validation:", securelink.sign.validate_md5_base64_url(secure_url, "secret", "127.0.0.1"))
print("❌ Invalid IP validation:", securelink.sign.validate_md5_base64_url(secure_url, "secret", "10.44.0.1"))
print("❌ Invalid secret validation:", securelink.sign.validate_md5_base64_url(secure_url, "wrong secret", "127.0.0.1"))
time.sleep(8)
print("⏳ Delayed validation:", securelink.sign.validate_md5_base64_url(secure_url, "secret", "127.0.0.1"))
🚀 Running as an API:
uvicorn securelink.api:app
INFO: Started server process [2928]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Once the API is running, you can access the interactive documentation at:
http://127.0.0.1:8000/docs
📌 Nginx Configuration Example
location ^~ /secure/ {
secure_link $arg_md5,$arg_expires;
secure_link_md5 "$secure_link_expires$uri$remote_addr secret";
if ($secure_link = "") {
return 403;
}
if ($secure_link = "0") {
return 410;
}
return 200;
}
📌 Notes
-
✅ The signature includes the expiration time, requested resource path, and client IP (if provided).
-
✅ The validation function ensures the signature is valid and the expiration time has not passed.
-
🔑 The secret key must be the same for both generation and validation.
-
⏳ The timestamp of Nginx and the URL signing app should be the same.
-
🌐 (nginx) The link can be accessed only from the client IP that was used for signing.
-
🔗 (nginx) Only the specified endpoint can be accessed using a single sign.
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file securelink-0.1.1.tar.gz.
File metadata
- Download URL: securelink-0.1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf6601f70caa06f3a58f22ba108550e75ef866a85d0b5233395884c31e7992b5
|
|
| MD5 |
87e3ade29573425c09b1a99ef4396a42
|
|
| BLAKE2b-256 |
89a8fa96d3fc73a92459cd63d1f5750df90d8c5f621b30c71215f50158f26e79
|
File details
Details for the file securelink-0.1.1-py3-none-any.whl.
File metadata
- Download URL: securelink-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a628b699e720a6a40b1a8420c06233baec1f40a82d45914bad30905b77008b34
|
|
| MD5 |
2ffc8c0decc6ea76f697d12c1fa63b52
|
|
| BLAKE2b-256 |
fc445285d5bdb3d9f4e30425a6edd9ddd76e95c7d052d25876ee89efefd1a966
|