-
-
Notifications
You must be signed in to change notification settings - Fork 275
Security: Potential sensitive data exposure via plaintext localStorage #1174
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,17 +7,28 @@ | |||||||||||||||||||||||||||||
| angular.module('ionic.utils', []) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| .factory('$localstorage', ['$window', function ($window) { | ||||||||||||||||||||||||||||||
| var sensitiveKeyPattern = /(pass(word)?|secret|token|auth|api[_-]?key|session|cookie|credential|jwt)/i; | ||||||||||||||||||||||||||||||
| function canStoreKey(key) { | ||||||||||||||||||||||||||||||
| return key && !sensitiveKeyPattern.test(key); | ||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+12
|
||||||||||||||||||||||||||||||
| function canStoreKey(key) { | |
| return key && !sensitiveKeyPattern.test(key); | |
| var allowedKeyPrefixes = ['app_', 'cfg_', 'config_', 'cache_', 'tmp_', 'pref_', 'prefs_', 'setting_', 'settings_', 'user_', 'profile_']; | |
| function canStoreKey(key) { | |
| if (typeof key !== 'string' || !key) { | |
| return false; | |
| } | |
| var hasAllowedPrefix = allowedKeyPrefixes.some(function (prefix) { | |
| return key.indexOf(prefix) === 0; | |
| }); | |
| if (!hasAllowedPrefix) { | |
| return false; | |
| } | |
| return !sensitiveKeyPattern.test(key); |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking writes by returning early is silent and can leave an existing sensitive value in localStorage untouched (if it was previously stored), increasing retention. Consider (1) removing any existing value for blocked keys (e.g., removeItem) and (2) surfacing the rejection to callers (throw, return a boolean, or log) so failures aren’t masked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex matches substrings like
authanywhere in the key, which can block unrelated keys such asauthorNameoroauthRedirect. Consider adding word/segment boundaries (e.g., start/end,_/-separators) or matching against a list of exact forbidden keys to reduce false positives.