Skip to content

Commit 8a4dd7e

Browse files
Joren BroekemadaKmoR
authored andcommitted
fix(field): delegate autocomplete to inputElement for security
1 parent 65a94c9 commit 8a4dd7e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/field/src/LionField.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export class LionField extends FormControlMixin(
4949
type: String,
5050
reflect: true,
5151
},
52+
autocomplete: {
53+
type: String,
54+
reflect: true,
55+
},
5256
};
5357
}
5458

@@ -141,6 +145,10 @@ export class LionField extends FormControlMixin(
141145
if (changedProps.has('name')) {
142146
this.inputElement.name = this.name;
143147
}
148+
149+
if (changedProps.has('autocomplete')) {
150+
this.inputElement.autocomplete = this.autocomplete;
151+
}
144152
}
145153

146154
/**

packages/field/test/lion-field.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ describe('<lion-field>', () => {
124124
expect(el.$$slot('input').value).to.equal('one');
125125
});
126126

127+
// This is necessary for security, so that inputElements autocomplete can be set to 'off'
128+
it('delegates autocomplete property', async () => {
129+
const el = await fixture(html`<${tag}>${inputSlot}</${tag}>`);
130+
expect(el.inputElement.autocomplete).to.equal('');
131+
expect(el.inputElement.hasAttribute('autocomplete')).to.be.false;
132+
el.autocomplete = 'off';
133+
await el.updateComplete;
134+
expect(el.inputElement.autocomplete).to.equal('off');
135+
expect(el.inputElement.getAttribute('autocomplete')).to.equal('off');
136+
});
137+
127138
// TODO: find out if we could put all listeners on this.value (instead of this.inputElement.value)
128139
// and make it act on this.value again
129140
it('has a class "state-filled" if this.value is filled', async () => {

0 commit comments

Comments
 (0)