zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
768 stars 390 forks source link

Security audit of ZIO HTTP #1535

Closed jdegoes closed 1 week ago

jdegoes commented 1 year ago

Is your feature request related to a problem? Please describe.

ZIO HTTP relies mostly on Netty, and therefore (largely) shares the security considerations of this project, while also benefiting from the large amount of work that has been done for Netty to identify and fix vulnerabilities and exploits.

That said, ZIO HTTP builds on and extends Netty in several ways that may introduce new vulnerabilities.

Describe the solution you'd like

A comprehensive security audit of ZIO HTTP in preparation for 1.0, including but not limited to:

  1. Use of ZIO Schema for decoding and encoding JSON (zio.http.api).
  2. Locally serving file content.
  3. Any middleware that interacts with in-memory structures (including metrics) or local file system
  4. Source for any and all configuration data
  5. All local disk access, environment variables, properties, and resources
  6. How any 'user data' coming from the request is used or incorporated into any response

Describe alternatives you've considered

NA

Additional context

Would be great to find a third-party firm to conduct an audit if the cost of such can be sponsored.

jdegoes commented 1 year ago

I'm going to define additional details and process for performing the security audit, which should be considered the "bare minimum" necessary to close this ticket:

  1. Creating a test suite for static file serving. The test suite should verify that it is impossible to escape the sandbox in which local files are being served, even in the presence of OS-specific symlinks (etc.).
  2. Creating various tests for any case in which potential user-data is turned into HTTP headers, cookies, content, etc. For example, HttpError turns (potentially user-defined) strings into content that is ultimately embedded into the response. This allows various security exploits such as XSS, which must be prevented through appropriate escaping. The tests should attempt to embed malicious data into the construction of errors, headers, responses, etc., and should demonstrate appropriate escape mechanisms are utilized to prevent these exploits.
  3. Creating a test suite that verifies any authentication code that ships with ZIO HTTP is not vulnerable to timing attacks. ZIO 2 has a data type called zio.Config.Secret that can be used to hold passwords, keys, etc., which can prevent timing attacks.
  4. Creating a test suite that attempts to crash the server (OOME) by generating extremely large: infinite URLs, infinite individual headers (e.g. Content-type: application/sjkldjfklsjdflkjsdkfljsdfljsdfk....), infinite total headers (each of which is small), infinite request bodies; infinite multi-part forms, etc.; and demonstrating that user-configurable limits on all of these are exposed and available and have reasonable defaults such that an out-of-the-box server is reasonably secure.
  5. Creating a test suite that demonstrates any built-in ZIO HTTP exception types do not leak stack trace or other sensitive information in HTTP responses.
  6. Creating a test suite designed to exercise any metrics that are built into ZIO HTTP, and verifying that it is not possible to run out of memory by, e.g., generating infinite URLs, infinite content types, etc.

/bounty $1500

algora-pbc[bot] commented 1 year ago

💎 $1,500 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #1535 with your implementation plan
  2. Submit work: Create a pull request including /claim #1535 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🔴 @feliciien Aug 18, 2023, 2:19:31 AM WIP
🔴 @Mayhul-Jindal Sep 24, 2023, 9:11:02 PM WIP
🔴 @pablf Aug 2, 2024, 4:53:31 PM #3039
Mayhul-Jindal commented 11 months ago

/attempt #1535

Options
algora-pbc[bot] commented 11 months ago

Note: The user @feliciien is already attempting to complete issue #1535 and claim the bounty. If you attempt to complete the same issue, there is a chance that @feliciien will complete the issue first, and be awarded the bounty. We recommend discussing with @feliciien and potentially collaborating on the same solution versus creating an alternate solution.

algora-pbc[bot] commented 11 months ago

@Mayhul-Jindal: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

algora-pbc[bot] commented 11 months ago

The bounty is up for grabs! Everyone is welcome to /attempt #1535 🙌

Mayhul-Jindal commented 11 months ago

/attempt #1535

feliciien commented 4 months ago

/attempt #1535

Subh231004 commented 3 months ago

Objective: To conduct a thorough security audit of ZIO HTTP in preparation for version 1.0, identifying potential vulnerabilities introduced by its extensions and ensuring robustness by leveraging the extensive security work already done for Netty.

Scope of the Audit: The audit will encompass the following key areas:

  1. ZIO Schema for Decoding and Encoding JSON (zio.http.api):

    • Evaluate the implementation of ZIO Schema for JSON processing.
    • Identify any potential security flaws in data serialization and deserialization.
    • Ensure proper validation and sanitization of input data to prevent injection attacks.
  2. Locally Serving File Content:

    • Review mechanisms for serving local files.
    • Check for directory traversal vulnerabilities.
    • Ensure proper access control to prevent unauthorized file access.
  3. Middleware Interaction with In-memory Structures and Local File System:

    • Assess middleware components for secure handling of in-memory data.
    • Evaluate metrics collection for potential data leaks or unauthorized access.
    • Review file system interactions for secure read/write operations and proper isolation.
  4. Source for Configuration Data:

    • Analyze the security of sources from which configuration data is loaded (e.g., environment variables, configuration files).
    • Ensure sensitive data in configurations is protected (e.g., credentials, API keys).
  5. Local Disk Access, Environment Variables, Properties, and Resources:

    • Evaluate access controls and permissions for local disk operations.
    • Ensure environment variables and properties are handled securely to prevent leakage of sensitive information.
    • Assess the security of accessing and using local resources.
  6. User Data Handling:

    • Examine how user data from requests is incorporated into responses.
    • Ensure that all user input is properly sanitized and validated.
    • Prevent cross-site scripting (XSS), cross-site request forgery (CSRF), and other injection attacks.

Methodology:

  1. Code Review:

    • Conduct a detailed review of the source code to identify potential security weaknesses.
    • Use static analysis tools to automate the detection of common vulnerabilities.
  2. Threat Modeling:

    • Identify and model potential threats specific to ZIO HTTP’s architecture and extensions.
    • Evaluate attack vectors and potential impact on the system.
  3. Penetration Testing:

    • Perform black-box and white-box penetration testing to simulate attacks and identify vulnerabilities.
    • Use automated tools as well as manual testing to cover a broad range of potential issues.
  4. Dependency Analysis:

    • Review third-party dependencies, especially Netty, to ensure no inherited vulnerabilities.
    • Ensure all dependencies are up-to-date and patched against known vulnerabilities.
  5. Configuration Review:

    • Analyze the default and custom configurations for security best practices.
    • Ensure configurations do not expose the application to unnecessary risks.
  6. Documentation Review:

    • Review existing documentation for accuracy and completeness regarding security practices.
    • Ensure that developers and users are well-informed about secure usage and deployment.

Deliverables:

  1. Audit Report:

    • Comprehensive documentation of identified vulnerabilities, their impact, and severity.
    • Detailed recommendations for mitigating each identified vulnerability.
  2. Remediation Plan:

    • Prioritized action plan for addressing and fixing vulnerabilities.
    • Guidance on secure coding practices to prevent future issues.
  3. Verification:

    • Follow-up assessment to verify that identified issues have been successfully mitigated.
    • Continuous monitoring recommendations to maintain security posture.

Alternatives Considered:

  1. Partial Audit:

    • Focusing only on high-risk areas such as JSON decoding and file serving, while deferring less critical components. However, this could miss vulnerabilities in other parts of the system.
  2. Automated Tools Only:

    • Relying solely on automated security tools for the audit. This approach is faster but may miss complex or context-specific vulnerabilities that require manual review.
  3. Internal Security Team:

    • Utilizing the internal development team for the audit. While they have deep knowledge of the system, they might lack specialized security expertise and objectivity.
Subh231004 commented 3 months ago

Is this resolved? Can I work on it?

pablf commented 1 month ago

/attempt #1535

Algora profile Completed bounties Tech Active attempts Options
@pablf    29 ZIO bounties
+ 1 bounty from 1 project
Scala, Rust
Cancel attempt
algora-pbc[bot] commented 1 month ago

@pablf: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

algora-pbc[bot] commented 3 weeks ago

The bounty is up for grabs! Everyone is welcome to /attempt #1535 🙌

algora-pbc[bot] commented 2 weeks ago

💡 @pablf submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] commented 1 week ago

🎉🎈 @pablf has been awarded $1,500! 🎈🎊