mirror of
https://github.com/itflow-org/itflow
synced 2026-11-21 11:57:25 +00:00
Keep browser autofill and password managers out of agent and admin forms by giving fields an unrecognised autocomplete value, new-password on password fields and the Bitwarden, 1Password, LastPass and Dashlane ignore attributes, leaving the agent's own profile, password change, current password and MFA code fields as they are
This commit is contained in:
@@ -215,6 +215,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
|
||||
|
||||
- Linking: Link - along the top of a record's page, on its tabs and in quick looks - opens a list right under it instead of a window. What's linked already is ticked: tick to link, untick to unlink, and it's saved when you click Done or anywhere else, with one message for what changed. It covers documents, files, assets, contacts, licenses, credentials, vendors, services, locations, domains and certificates, a contact's assets and credentials and an asset's credentials, a project's and a service's tickets, a ticket's services and its related tickets. A document's or file's Link lists every kind it can be linked to, in groups. Tickets are no longer added to a project by typing their numbers - tick them in the list (open ones and those closed in the last 90 days), or change the project on the ticket.
|
||||
- Sign-in codes: the 6-digit code - signing in with two-step sign-in, setting it up (yours, or a contact's in the client portal), and the code emailed for a shared link - goes in six boxes, three and three. Paste or let your phone or password manager fill it, "123 456" too, and it goes as soon as the sixth digit is in - no need to click the button. A wrong code turns the boxes red. On the sign-in page Remember this browser now comes before the code, so tick it first.
|
||||
- Browser autofill: Chrome, Edge and other Chromium browsers no longer offer your own name, email, phone or address in forms about clients - a new client's contact, a contact, a location - and Bitwarden, 1Password, LastPass and Dashlane no longer offer your ITFlow login in a credential's username and password, or anywhere else you type someone else's details or secrets, nor ask to save them. Your own profile, password change and two-step sign-in still work with your password manager.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -424,6 +425,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
|
||||
- Tab rows: `js/tab_fold.js` (loaded by `includes/footer.php`) folds the tabs that don't fit into a More dropdown, from the end, never the `.active` one - in `.nav.itflow-asset-tabs` (or a `.nav` inside an `.itflow-asset-tabs` card header), `.nav.itflow-asset-pills`, `.nav.itflow-asset-form-tabs` and any `.nav.itflow-tabs-foldable` (added to the kinds in Admin > Categories and Tags and to the mail settings tabs). A tab is a `.nav-link` of the row or the `.nav-item` around one; rows in a window are set up on `shown.bs.modal`, and a row laid out as a column, or not on screen yet, is left as it is. Folded tabs stay in place with `.itflow-tab-folded`, so Bootstrap's tabs and page scripts keep working on them; More is a `.nav-link.dropdown-toggle` (left out by Bootstrap's tabs and by `agent/js/tickets_live.js`), and its items are built on `show.bs.dropdown` - a link for a tab with an href, otherwise a button that clicks the tab. The row gets `.itflow-tabs-fold` (one line, overflow visible, min-width 0, its tabs `nowrap`), and fits again on resize, font load and any change to its tabs (a MutationObserver - counts updated in place, the open tab changing).
|
||||
- Link picker: `functions/link_picker.php` (`linkPickerButton()`, `linkPickerSource()`, `linkPickerOptions()`, `linkPickerSave()`, `LINK_PICKER_OWN` for the links that aren't `LINK_RELATIONS` pairs), `js/link_picker.js`, and `agent/ajax.php` `link_picker` (GET: the options, linked ones selected) and `link_picker_save` (POST `add[]` and `remove[]`; `flash=1` keeps the message for the page it reloads). It opens the select picker on a hidden multiple `<select>`: in `js/itflow_select.js` a picker's `.anchor` puts the panel under that element, and closing fires `itflow:close`. With no `to`, the options are grouped by kind and their values are `type:id`. The link windows (`agent/modals/link/link.php` and its one-pair wrappers, `contact_link_asset.php`, `contact_link_credential.php`, `asset_link_credential.php`, `project_link_ticket.php`, `service_link_ticket.php`, `ticket_link_service.php`, `ticket_link.php`) and the handlers only they posted to (`link_items`, `link_tickets`, `link_service_tickets`, `link_ticket_services`, `link_ticket_to_project`, `link_contact_to_asset`, `link_contact_to_credential`, `link_asset_to_credential`) are gone; the unlink handlers stay. `js/ajax_modal.js` keeps a window's URL in `data-modal-url`, so a quick look loads again in place after a change, and `js/tab_fold.js` exposes `window.itflowTabFold()`.
|
||||
- Code boxes: `otpCodeInput()` in `functions/user.php` draws a 6-digit code field (options: id, label, class, autofocus, submit, invalid) and `js/otp_input.js` (loaded by `includes/footer.php`, `client/includes/footer.php`, `login.php`, `agent/user/mfa_enforcement.php` and `guest/share.php`) lays the one see-through input over six `.itflow-otp-slot` boxes - typing, paste and autofill go to the input, the boxes only show it. Non-digits are stripped (a pasted "123 456" fills them all), the caret stays at the end, a value set from script redraws them (the input's own `value` property), and the `is-invalid` class on the input turns them red until the next digit. `data-otp-submit` sends the form with `requestSubmit()` and its first submit button once the sixth digit is in; `window.itflowOtp(input)` does one added later. One with `autofocus` is focused (without scrolling) when its modal opens (`shown.bs.modal`), and on load when the browser skipped it - a page opened at a `#fragment`. `login.php` (agent and client steps), `agent/user/includes/mfa_setup.php`, `client/profile.php` and `guest/share.php` use it; `.itflow-mfa-code` is gone.
|
||||
- Autofill: `js/autofill_off.js` (loaded by `includes/footer.php` on agent and admin pages, not the guest portal) gives every input, textarea and select whose autocomplete is missing, `off` or `new-password` an unrecognised `autocomplete="itflow-none"` (Chromium offers no autofill or past entries for one, where it ignores `off` for names and addresses) - `new-password` on password fields, so the saved ITFlow login isn't offered - plus `data-1p-ignore`, `data-lpignore`, `data-bwignore` and `data-form-type="other"`, and marks it `data-autofill-off`. Fields added later are done by a `MutationObserver`, which also puts it back when a script sets `autocomplete="off"` again (`js/autocomplete.js`). Left alone: `current-password`, `username`, `one-time-code`, any other real autofill value, and anything inside `[data-autofill]` - `#profileForm` and `#passwordForm` in Your account.
|
||||
|
||||
## [26.11.8]
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ $has_avatar = trim((string) $me['user_avatar']) !== '';
|
||||
<div class="card-header bg-dark">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-id-badge me-2"></i>Profile</h3>
|
||||
</div>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off" id="profileForm">
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off" id="profileForm" data-autofill>
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
@@ -24,7 +24,7 @@ $remember_days = max(1, intval($config_login_remember_me_expire));
|
||||
<div class="card-header bg-dark">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-key me-2"></i>Password</h3>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off" id="passwordForm">
|
||||
<form action="post.php" method="post" autocomplete="off" id="passwordForm" data-autofill>
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
|
||||
@@ -58,6 +58,12 @@
|
||||
comment - and all of those still run well after this block. */ ?>
|
||||
<script src="<?= staticFileUrl('/js/itflow_select.js') ?>"></script>
|
||||
|
||||
<?php /* Browser autofill and password managers kept out of agents' forms - they're about
|
||||
clients, not the agent. Before anything else draws fields; the guest portal keeps them. */ ?>
|
||||
<?php if (basename(dirname($_SERVER['REQUEST_URI'])) !== 'guest') { ?>
|
||||
<script src="<?= staticFileUrl('/js/autofill_off.js') ?>"></script>
|
||||
<?php } ?>
|
||||
|
||||
<!-- Bootstrap 5 -->
|
||||
<script src="<?= staticFileUrl('/libs/bootstrap/js/bootstrap.bundle.min.js') ?>"></script>
|
||||
<script src="<?= staticFileUrl('/js/bootstrap_defaults.js') ?>"></script>
|
||||
|
||||
81
js/autofill_off.js
Normal file
81
js/autofill_off.js
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Keeps the browser's autofill and password managers out of ITFlow's forms.
|
||||
* What agents type here is about clients, their people and their logins - not
|
||||
* about the agent - so Chrome or Edge offering the agent's own name, email,
|
||||
* phone or address, or Bitwarden, 1Password, LastPass or Dashlane offering the
|
||||
* agent's ITFlow login, only fills in the wrong thing.
|
||||
*
|
||||
* Each field gets:
|
||||
* - an autocomplete value no browser knows, so Chromium browsers offer nothing.
|
||||
* They ignore autocomplete="off" for names and addresses, but not this.
|
||||
* - new-password on a password field instead, so the saved ITFlow login isn't
|
||||
* offered.
|
||||
* - each password manager's own attribute for leaving a field alone, which also
|
||||
* stops them offering to save what's typed.
|
||||
*
|
||||
* Left as they are:
|
||||
* - fields asking for the agent's own password or code (current-password,
|
||||
* username, one-time-code);
|
||||
* - fields with another real autocomplete value someone chose on purpose;
|
||||
* - anything inside [data-autofill] - the agent's own profile and password
|
||||
* change.
|
||||
*
|
||||
* Fields on the page are done straight away, and any added later (windows,
|
||||
* quick add) as they arrive - and again if a script sets autocomplete="off"
|
||||
* on one afterwards. Agent and admin pages only (includes/footer.php).
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
const SELECTOR = 'input, textarea, select';
|
||||
const SKIP_TYPES = ['hidden', 'checkbox', 'radio', 'file', 'submit', 'button', 'reset', 'image', 'range', 'color'];
|
||||
const NONE = 'itflow-none';
|
||||
|
||||
function guard(field) {
|
||||
if ((field.tagName === 'INPUT' && SKIP_TYPES.indexOf(field.type) !== -1)
|
||||
|| field.closest('[data-autofill]')) {
|
||||
return;
|
||||
}
|
||||
const current = (field.getAttribute('autocomplete') || '').trim().toLowerCase();
|
||||
if (current !== '' && current !== 'off' && current !== 'new-password') {
|
||||
return;
|
||||
}
|
||||
const value = field.type === 'password' || current === 'new-password' ? 'new-password' : NONE;
|
||||
if (current !== value) {
|
||||
field.setAttribute('autocomplete', value);
|
||||
}
|
||||
if (field.hasAttribute('data-autofill-off')) {
|
||||
return;
|
||||
}
|
||||
field.setAttribute('data-1p-ignore', '');
|
||||
field.setAttribute('data-lpignore', 'true');
|
||||
field.setAttribute('data-bwignore', 'true');
|
||||
field.setAttribute('data-form-type', 'other');
|
||||
field.setAttribute('data-autofill-off', '');
|
||||
}
|
||||
|
||||
function guardWithin(node) {
|
||||
if (node.nodeType !== 1) {
|
||||
return;
|
||||
}
|
||||
if (node.matches(SELECTOR)) {
|
||||
guard(node);
|
||||
}
|
||||
node.querySelectorAll(SELECTOR).forEach(guard);
|
||||
}
|
||||
|
||||
guardWithin(document.documentElement);
|
||||
|
||||
// New fields, and a field's script setting autocomplete="off" on it again (js/autocomplete.js)
|
||||
new MutationObserver(function (mutations) {
|
||||
mutations.forEach(function (mutation) {
|
||||
if (mutation.type === 'attributes') {
|
||||
if (mutation.target.hasAttribute('data-autofill-off')) {
|
||||
guard(mutation.target);
|
||||
}
|
||||
return;
|
||||
}
|
||||
mutation.addedNodes.forEach(guardWithin);
|
||||
});
|
||||
}).observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeFilter: ['autocomplete'] });
|
||||
})();
|
||||
Reference in New Issue
Block a user