Skip to content

Latest commit

 

History

History
147 lines (110 loc) · 10.9 KB

File metadata and controls

147 lines (110 loc) · 10.9 KB

Mitigation Strategies Analysis for apollographql/apollo-android

  • Description:

    1. Documentation Review: Android developers, using apollo-android, review the documented limits provided by the backend team (regarding query complexity and depth).
    2. Client-Side Design: Design GraphQL queries within the apollo-android client (in .graphql files or programmatically) to stay within the server's defined limits. Avoid deeply nested or overly complex queries.
    3. Error Handling: Implement error handling in the apollo-android client to detect server responses indicating query complexity violations (typically a specific error code or message in the GraphQL error response). Use apollo-android's error handling mechanisms.
    4. User Feedback: When a complexity violation occurs, provide user-friendly feedback (e.g., "Your request is too complex. Please simplify it."). Do not expose raw error messages from the server.
    5. Testing: Write unit and integration tests using apollo-android that deliberately send complex queries to verify the server's enforcement and the client's error handling.
  • Threats Mitigated:

    • Denial of Service (DoS) due to Complex Queries: (Severity: High) - Client-side awareness helps prevent sending queries that would be rejected by the server.
    • Resource Exhaustion: (Severity: Medium) - Client avoids sending unnecessarily resource-intensive queries.
  • Impact:

    • DoS due to Complex Queries: Risk reduced. The client is designed to avoid triggering the issue.
    • Resource Exhaustion: Risk reduced. Client-side awareness helps minimize the likelihood of sending resource-intensive queries.
  • Currently Implemented:

    • Error handling for GraphQL errors is implemented in NetworkClient.kt.
    • Basic query structure is defined in .graphql files.
  • Missing Implementation:

    • Specific tests for query complexity violations are missing.
    • No explicit design considerations to minimize query complexity within the apollo-android client code.

Mitigation Strategy: Use Persisted Queries

  • Description:

    1. Client-Side Integration: Configure the apollo-android client to use persisted queries. Instead of sending the full query string with each request, the client sends the identifier (hash or ID) of the pre-registered query. This requires using apollo-android's APIs for persisted queries.
    2. Automated Generation (with Client Integration): Integrate a tool (like apollo-tooling) into the Android build process. This tool should:
      • Automatically extract GraphQL queries from the project (e.g., from .graphql files).
      • Generate a manifest of persisted queries (mapping query strings to identifiers).
      • Potentially upload the manifest to the server (depending on the server's setup).
      • Configure apollo-android to use the generated manifest.
  • Threats Mitigated:

    • Arbitrary Query Injection: (Severity: High) - The client cannot send arbitrary queries; it only sends pre-approved identifiers.
    • Reduced Attack Surface: (Severity: Medium) - The server only exposes a limited set of operations.
  • Impact:

    • Arbitrary Query Injection: Risk almost entirely eliminated from the client-side perspective.
    • Reduced Attack Surface: Significant reduction in attack surface.
  • Currently Implemented:

    • None. The project currently sends full query strings using apollo-android.
  • Missing Implementation:

    • Entirely missing. Requires client-side changes and build process integration with apollo-android.
  • Description:

    1. Error Parsing: Use apollo-android's error handling capabilities (e.g., ApolloCall.Callback, ApolloException) to parse GraphQL error responses. Extract relevant information (error code, message, extensions, path).
    2. Sanitization: Never directly display raw error messages from the server to the user. Sanitize the error information within the apollo-android client code, removing any potentially sensitive details.
    3. User-Friendly Messages: Create user-friendly error messages based on the parsed and sanitized error information. Provide helpful guidance to the user, appropriate for the application's context.
    4. Secure Logging: When logging errors for debugging within the apollo-android client, be extremely careful not to log sensitive data that might be present in the raw error response. Redact or remove any sensitive information before logging.
    5. Error Classification: Within the apollo-android client, differentiate between different types of GraphQL errors (e.g., validation errors, authorization errors, internal server errors) and handle them appropriately (different UI treatment, retry logic, etc.).
  • Threats Mitigated:

    • Information Disclosure via Error Messages: (Severity: Medium) - Prevents leaking sensitive information through error messages displayed by the apollo-android client.
    • Improved User Experience: (Severity: Low) - Provides more helpful and less confusing error messages.
  • Impact:

    • Information Disclosure: Risk significantly reduced. Raw error messages are not exposed by the client.
    • Improved User Experience: Positive impact on user experience.
  • Currently Implemented:

    • Basic error parsing is done in NetworkClient.kt using apollo-android's APIs.
  • Missing Implementation:

    • No sanitization of error messages before displaying them to the user within the apollo-android client.
    • No secure logging practices in place for error handling within the client.
    • No differentiation between different types of GraphQL errors within the client's error handling logic.
  • Description:

    1. Secure Storage: Use Android's Keystore system (or a similarly secure mechanism) to store authentication tokens. Do not store tokens in SharedPreferences, plain text files, or other insecure locations.
    2. Token Retrieval: Retrieve tokens from secure storage only when needed for a request.
    3. HTTP Headers: Use standard HTTP headers (e.g., Authorization: Bearer <token>) to include the token in requests to the GraphQL server. Use apollo-android's interceptor capabilities (e.g., addApplicationInterceptor) to add the authentication header to each request.
    4. Token Refresh: Implement a token refresh mechanism using apollo-android's interceptor capabilities. The interceptor should:
      • Check for token expiration before sending a request.
      • If the token is expired, attempt to refresh it (using a refresh token or other mechanism).
      • If the refresh is successful, update the stored token and retry the original request.
      • If the refresh fails, handle the authentication failure appropriately (e.g., redirect to login).
    5. Logout: When user logout, securely remove token from storage.
  • Threats Mitigated:

    • Token Theft: (Severity: High) - Reduces the risk of attackers stealing authentication tokens.
    • Unauthorized Access: (Severity: High) - Prevents unauthorized access if a token is compromised or expired.
  • Impact:

    • Token Theft: Risk significantly reduced by using secure storage.
    • Unauthorized Access: Risk reduced by proper token handling and refresh mechanisms, implemented using apollo-android's features.
  • Currently Implemented:

    • Tokens are stored in SharedPreferences (INSECURE!).
    • HTTP headers are used for authentication via apollo-android's interceptors.
  • Missing Implementation:

    • Secure storage using Android Keystore is not implemented.
    • Token refresh mechanism is not implemented using apollo-android's interceptor capabilities.
  • Description:

    1. Test Environment: Set up a test environment that mimics the production environment, specifically with GraphQL introspection disabled on the server.
    2. Client-Side Tests: Write tests using apollo-android that attempt to perform introspection queries.
    3. Error Handling Verification: Ensure that the apollo-android client gracefully handles the errors that occur when introspection is disabled. Verify that the application functions correctly even without introspection.
    4. No reliance on introspection: Ensure that production code does not rely on introspection.
  • Threats Mitigated:

    • Schema Exposure (Indirectly): (Severity: Medium) - Ensures the client doesn't break if introspection is disabled, supporting the server-side mitigation.
    • Reliance on Introspection: (Severity: Low) - Prevents the client from relying on a feature that may not be available.
  • Impact:

    • Schema Exposure: Indirectly supports the server-side mitigation.
    • Reliance on Introspection: Prevents unexpected behavior in production.
  • Currently Implemented:

    • None.
  • Missing Implementation:

    • Client-side testing against an environment without introspection is not explicitly done.
    • Error handling for failed introspection attempts is not specifically implemented or tested within the apollo-android client.

Mitigation Strategy: Keep Dependencies Updated

  • Description:

    1. Regular Updates: Regularly check for updates to the apollo-android library itself using Gradle. Update to the latest stable version.
    2. Vulnerability Scanning: Although this is a general practice, it directly impacts apollo-android. Use a vulnerability scanner to check for known vulnerabilities in apollo-android and its transitive dependencies.
  • Threats Mitigated:

    • Known Vulnerabilities in apollo-android: (Severity: Variable, can be High) - Reduces the risk of exploiting known vulnerabilities in the apollo-android library.
  • Impact:

    • Known Vulnerabilities: Risk significantly reduced by keeping apollo-android up-to-date.
  • Currently Implemented:

    • Gradle is used for dependency management.
  • Missing Implementation:

    • No regular, scheduled updates of the apollo-android library.
    • No vulnerability scanning specifically targeting apollo-android and its dependencies.