Skip to content

feat: Custom Login Fields per-domain selectors#58

Merged
hieuck merged 1 commit into
mainfrom
feature/custom-login-fields
Jul 8, 2026
Merged

feat: Custom Login Fields per-domain selectors#58
hieuck merged 1 commit into
mainfrom
feature/custom-login-fields

Conversation

@hieuck

@hieuck hieuck commented Jul 8, 2026

Copy link
Copy Markdown
Owner

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)

    • Domain normalization.
    • getCustomLoginFields(domainOrUrl) / setCustomLoginField(...) / clearCustomLoginFields(...) backed by chrome.storage.local.
    • findCustomFields(root, mapping) resolves stored selectors to DOM elements.
  • extension/contentScript.js

    • Loads the domain's custom field mapping on startup.
    • findPasswordInput, findUsernameInput, and findOtpInput now check for a custom selector first and fall back to the existing heuristic logic.
    • Defensive fallbacks keep the content script working when imports are stripped in the vm-based test sandbox.
  • tests/unit/custom-login-fields.test.mjs (new)

    • 9 tests covering domain normalization, storage round-trips, invalid roles, clearing, and findCustomFields resolution.

Verification

  • npm test — 1017 tests passed (76 test files)
  • npm run lint — clean

- 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-tools

ecc-tools Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@hieuck, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 31a6b391-e5f0-4a9b-bb19-22086304e085

📥 Commits

Reviewing files that changed from the base of the PR and between 238ad38 and 2573fc0.

📒 Files selected for processing (3)
  • extension/contentScript.js
  • extension/shared/custom-login-fields.js
  • tests/unit/custom-login-fields.test.mjs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/custom-login-fields

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment on lines +56 to +72
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +24 to +43
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hieuck hieuck merged commit a235a15 into main Jul 8, 2026
17 checks passed
@hieuck hieuck deleted the feature/custom-login-fields branch July 8, 2026 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Custom Login Fields support

1 participant