Skip to content

[Security] Multiple Unsafe JSON.parseExn Usages #4732

Description

@muditbhutani

Summary

JSON.parseExn throws an exception on invalid JSON input. Several call sites use it on untrusted data (sessionStorage, DOM events, API error messages) without adequate error handling, which can cause application crashes or expose unexpected behavior.

Affected Locations

# File Line Input Source Error Handling Risk
1 src/context/FilterContext.res 177 sessionStorage None HIGH
2 src/components/HandlingEvents.res 12 postMessage DOM event try/catch present MEDIUM
3 src/screens/Developer/PaymentSettingsRevamped/AcquirerConfigSettingsRevamp/AcquirerConfigSettingsRevamp.res 62 API error message outer try/catch only MEDIUM
4 src/screens/Developer/PaymentSettings/AcquirerConfigSettings/AcquirerConfigSettings.res 61 API error message outer try/catch only MEDIUM
5 src/screens/PaymentLinkThemeConfigurator/PaymentLinkThemeConfiguratorTool.res 61 WASM return value outer try/catch only MEDIUM

src/utils/LogicUtils.res line 36 (safeParseOpt) is a safe wrapper and is not an issue.

Highest-Risk Case — FilterContext.res Line 177

switch sessionStorage.getItem(`${index}-list`)->Nullable.toOption {
| Some(value) =>
  switch value->JSON.parseExn->JSON.Decode.array {   // <-- no try/catch
  | Some(arr) => ...
  | None => ()
  }
| None => ()
}

sessionStorage can be written by any same-origin JavaScript. If the stored value is malformed JSON, JSON.parseExn throws an unhandled exception that crashes the filter context, breaking the dashboard UI.

Impact

  • FilterContext crash: corrupted or attacker-manipulated sessionStorage can force an unhandled exception, making filters non-functional
  • Cascading failures: other call sites with only outer-scope try/catch may silently swallow errors and leave the UI in an inconsistent state

Severity: MEDIUM–HIGH

Recommended Fix

  1. FilterContext.res line 177 — wrap with an immediate try/catch or use LogicUtils.safeParseOpt instead of JSON.parseExn
  2. All other sites — replace JSON.parseExn on untrusted sources with LogicUtils.safeParseOpt and handle the None case explicitly
  3. Establish a lint rule or code review checklist item: JSON.parseExn must never be called without a surrounding try/catch or a safe-parse wrapper when the source is external (API, storage, events)

References

Metadata

Metadata

Assignees

Labels

C-bugCategory: Bugverified-canpickVerified issue, ready to be picked up

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions