feat: Custom Login Fields per-domain selectors#58
Conversation
- Add extension/shared/custom-login-fields.js for storage and DOM lookup. - contentScript.js now uses custom username/password/TOTP selectors first, falling back to heuristic detection. - Add unit tests covering storage, normalization, invalid roles, and lookup. Closes #57
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
|
Warning Review limit reached
Next review available in: 58 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| export function findCustomFields(root, mapping) { | ||
| if (!mapping) return null; | ||
| const result = {}; | ||
| for (const role of VALID_ROLES) { | ||
| const selector = mapping[role]; | ||
| if (selector) { | ||
| try { | ||
| result[role] = root.querySelector(selector) || null; | ||
| } catch { | ||
| result[role] = null; | ||
| } | ||
| } else { | ||
| result[role] = null; | ||
| } | ||
| } | ||
| return result; | ||
| } |
There was a problem hiding this comment.
Potential Security and Stability Issue with Selectors
The findCustomFields function uses selectors from user-controlled storage in root.querySelector(selector). While a try/catch block is present, this does not prevent the use of overly broad, inefficient, or potentially malicious selectors that could impact performance or cause unexpected behavior. Consider validating or restricting the allowed selector patterns to mitigate risks.
Recommendation:
- Implement stricter validation or sanitization of selectors before storing or using them.
- Optionally, limit the length or complexity of selectors to avoid performance issues.
| export async function setCustomLoginField(domainOrUrl, role, selector) { | ||
| const domain = normalizeDomain(domainOrUrl); | ||
| if (!domain) { | ||
| throw new Error('Invalid domain'); | ||
| } | ||
| if (!VALID_ROLES.has(role)) { | ||
| throw new Error(`Invalid role: ${role}. Must be one of ${[...VALID_ROLES].join(', ')}`); | ||
| } | ||
| if (!selector || typeof selector !== 'string') { | ||
| throw new Error('Selector must be a non-empty string'); | ||
| } | ||
|
|
||
| const settings = await getSettings(); | ||
| const all = settings[STORAGE_KEY] || {}; | ||
| const current = { ...(all[domain] || {}) }; | ||
| current[role] = selector; | ||
| all[domain] = current; | ||
| await setSettings({ [STORAGE_KEY]: all }); | ||
| return current; | ||
| } |
There was a problem hiding this comment.
Possible Inconsistent Role-Selector Mapping
In setCustomLoginField, the function allows the same selector to be assigned to multiple roles for a domain without warning or deduplication. This could lead to ambiguous or conflicting mappings if, for example, both 'username' and 'password' are mapped to the same selector.
Recommendation:
- Consider checking for and preventing duplicate selectors across roles for the same domain, or at least warn the user if such a situation occurs.
Summary
Adds a foundational Custom Login Fields feature that lets KeePassBrowserBridge use per-domain CSS-selector mappings for username, password, and TOTP fields when heuristics fail.
Closes #57
Changes
extension/shared/custom-login-fields.js(new)getCustomLoginFields(domainOrUrl)/setCustomLoginField(...)/clearCustomLoginFields(...)backed bychrome.storage.local.findCustomFields(root, mapping)resolves stored selectors to DOM elements.extension/contentScript.jsfindPasswordInput,findUsernameInput, andfindOtpInputnow check for a custom selector first and fall back to the existing heuristic logic.tests/unit/custom-login-fields.test.mjs(new)findCustomFieldsresolution.Verification
npm test— 1017 tests passed (76 test files)npm run lint— clean