Skip to content

Unhandled FormatException crash during JSON decoding in NetworkService #1051

@vibhutomer

Description

@vibhutomer

Description

In NetworkServiceImpl.getVersionNoApp(), the application parses the network response directly using jsonDecode(response.body) without a surrounding try-catch block for format exceptions.

While the code checks for response.statusCode == 200, this does not guarantee the payload is valid JSON. If a proxy, firewall, or server misconfiguration intercepts the request and returns an HTML payload or an empty string with a 200 status, jsonDecode will immediately throw a fatal FormatException (e.g., Unexpected character). Because this exception is unhandled, it bypasses the normal error flow and causes a hard application crash.

Steps to Reproduce

  1. Intercept the network request to the actuator endpoint (using a tool like Charles Proxy or Postman).
  2. Return a 200 OK status, but change the response body to an empty string "" or a basic HTML string <html>Error</html>.
  3. Trigger the network call in the app.
  4. Observe the immediate FormatException and fatal runtime crash in the console.

Expected Behavior

Network payloads must be treated as untrusted data. jsonDecode should be wrapped in a try-catch block specifically catching FormatException. If parsing fails, the app should gracefully handle it (e.g., returning a default value or showing an error UI) instead of crashing.

Environment

  • Target File: network_service_impl.dart

Proposed Solution

Wrap the jsonDecode logic inside a try-catch block. Catch the FormatException, log the parsing error, and handle the failure state safely without bringing down the application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions