Describe the bug
The public SDK helpers getAnonymousId() and getSessionId() read from localStorage and sessionStorage without handling storage access errors.
Web Storage access can throw a DOMException such as SecurityError when storage is restricted by browser settings or unavailable in a sandboxed context. When this happens, these helpers throw instead of treating the tracking ID as unavailable.
The error also propagates through:
getTrackingIds()
getTrackingParams()
This differs from getProfileId(), which already catches storage errors and returns null.
This can affect user-facing flows that treat tracking information as optional metadata. For example, Stripe checkout metadata and contact-form submission both call getTrackingIds().
To Reproduce
- Load
@databuddy/sdk in a browser.
- Override storage reads to simulate a restricted-storage environment:
const originalGetItem = Storage.prototype.getItem;
Storage.prototype.getItem = function () {
throw new DOMException("Access is denied", "SecurityError");
};
try {
getAnonymousId();
} finally {
Storage.prototype.getItem = originalGetItem;
}
- Observe that
getAnonymousId() throws SecurityError.
The same behavior occurs when getSessionId() encounters an inaccessible sessionStorage. The exception also propagates from getTrackingIds() and getTrackingParams().
Expected behavior
Storage access failures should be treated as missing tracking IDs:
getAnonymousId(); // null
getSessionId(); // null
getTrackingIds(); // { anonId: null, sessionId: null }
getTrackingParams(); // ""
If only one storage mechanism is unavailable, getTrackingIds() and getTrackingParams() should preserve the ID available from the other mechanism.
Explicit URLSearchParams values should continue to take priority without accessing the corresponding storage mechanism.
Screenshots
Not applicable. The failure is a thrown DOMException.
Environment (please complete the following information):
- OS: windows 11
- Browser: firefox
- Version: 154.0
- SDK version:
@databuddy/sdk 2.6.0
Additional context
The affected code is in packages/sdk/src/core/tracker.ts.
Existing tests cover empty storage, populated storage, and URL-parameter precedence, but do not cover storage reads throwing.
A fix could follow the existing getProfileId() pattern by catching errors around each individual storage read and returning null.
AI usage disclosure
This issue report was drafted with OpenAI Codex. Codex inspected the affected SDK implementation, its call sites, existing tests, repository history, contribution guidelines, and AI usage policy. I personally reviewed and edited the report and reproduced the behavior before submission.
Describe the bug
The public SDK helpers
getAnonymousId()andgetSessionId()read fromlocalStorageandsessionStoragewithout handling storage access errors.Web Storage access can throw a
DOMExceptionsuch asSecurityErrorwhen storage is restricted by browser settings or unavailable in a sandboxed context. When this happens, these helpers throw instead of treating the tracking ID as unavailable.The error also propagates through:
getTrackingIds()getTrackingParams()This differs from
getProfileId(), which already catches storage errors and returnsnull.This can affect user-facing flows that treat tracking information as optional metadata. For example, Stripe checkout metadata and contact-form submission both call
getTrackingIds().To Reproduce
@databuddy/sdkin a browser.getAnonymousId()throwsSecurityError.The same behavior occurs when
getSessionId()encounters an inaccessiblesessionStorage. The exception also propagates fromgetTrackingIds()andgetTrackingParams().Expected behavior
Storage access failures should be treated as missing tracking IDs:
If only one storage mechanism is unavailable,
getTrackingIds()andgetTrackingParams()should preserve the ID available from the other mechanism.Explicit
URLSearchParamsvalues should continue to take priority without accessing the corresponding storage mechanism.Screenshots
Not applicable. The failure is a thrown
DOMException.Environment (please complete the following information):
@databuddy/sdk2.6.0Additional context
The affected code is in
packages/sdk/src/core/tracker.ts.Existing tests cover empty storage, populated storage, and URL-parameter precedence, but do not cover storage reads throwing.
A fix could follow the existing
getProfileId()pattern by catching errors around each individual storage read and returningnull.AI usage disclosure
This issue report was drafted with OpenAI Codex. Codex inspected the affected SDK implementation, its call sites, existing tests, repository history, contribution guidelines, and AI usage policy. I personally reviewed and edited the report and reproduced the behavior before submission.