Skip to content

Adapt Cloudflare Web Security #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 5, 2025
Merged

Adapt Cloudflare Web Security #43

merged 14 commits into from
Jul 5, 2025

Conversation

Masterain98
Copy link
Member

No description provided.

@Masterain98 Masterain98 requested review from Lightczx and qhy040404 July 3, 2025 05:24
@Masterain98 Masterain98 self-assigned this Jul 3, 2025
@Masterain98 Masterain98 added the enhancement New feature or request label Jul 3, 2025
@dgp-bot
Copy link

dgp-bot bot commented Jul 3, 2025

Introducing Cloudflare Security Tools

This pull request by Masterain introduces and integrates Cloudflare security tools into the FastAPI application.

Changes by feature
  • Cloudflare Security Utils Integration:

    • Adds a submodule for cloudflare_security_utils from https://github.com/DGP-Studio/cloudflare-api-security.git.
    • Syncs the submodule to the latest commits.
  • Refactor: Client Verification

    • Removes validate_client_is_updated from utils/dgp_utils.py and integrates its functionality within the cloudflare_security_utils.
    • Migrates mgnt router to cloudflare_security_utils, remove routers/mgnt.py
  • Client Feature Router Security:

    • Integrates enhanced_safety_check from cloudflare_security_utils as a dependency for the client_feature router endpoints (china_router, global_router, fujian_router). This check is applied to the GET requests for file paths.
    • Refactors the client_feature handlers to return safety_check as RedirectResponse if applicable.

Key Change Highlights

  • Submodule Inclusion: The addition of the cloudflare_security_utils submodule brings in external security measures. This is a critical addition as it centralizes security-related functionalities.
  • Dependency Injection for Security: The enhanced_safety_check is now a dependency for the client feature endpoints. This means that every request to these endpoints will undergo a security check before being processed. This could affect the performance and behavior of these endpoints, as all requests will now be validated against the security policies defined in the submodule.
  • Configuration Changes:
    • The SERVER_TYPE variable in config.py is now lowercased for comparison, ensuring consistency.
    • The IS_DEBUG flag is determined based on whether "alpha" or "dev" is in the SERVER_TYPE string.

Suggested Test Methods

  • API Endpoint Tests for Client Feature Router:
    • Verify that the enhanced_safety_check dependency is correctly applied to all endpoints in the client_feature router.
    • Test different scenarios (e.g., valid vs. invalid requests) to ensure that the security checks work as expected and return the correct responses (either processing the request or redirecting).
  • Submodule Integration Tests:
    • Ensure the cloudflare_security_utils submodule is correctly initialized and updated.
    • Verify that the functions within the submodule (e.g., enhanced_safety_check) are functioning as expected.
  • Configuration Tests:
    • Confirm that the IS_DEBUG flag is correctly set based on the SERVER_TYPE environment variable.
    • Test the application in different environments (e.g., development, alpha, production) to ensure that the configuration is correctly loaded and applied.

Copy link
Member

@qhy040404 qhy040404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@Masterain98 Masterain98 merged commit 279a7f7 into main Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants