Skip to content

Commit 3ea9ac5

Browse files
committed
fix(core): prevent handling of not trusted touch events
fixes #4164
1 parent 411bfce commit 3ea9ac5

7 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/core/components/calendar/calendar-class.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Calendar extends Framework7Class {
168168
const { $el, $wrapperEl } = calendar;
169169

170170
function handleTouchStart(e) {
171-
if (isMoved || isTouched) return;
171+
if (isMoved || isTouched || !e.isTrusted) return;
172172
isTouched = true;
173173
touchStartX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
174174
touchCurrentX = touchStartX;
@@ -181,7 +181,7 @@ class Calendar extends Framework7Class {
181181
currentTranslate = calendar.monthsTranslate;
182182
}
183183
function handleTouchMove(e) {
184-
if (!isTouched) return;
184+
if (!isTouched || !e.isTrusted) return;
185185
const { isHorizontal: isH } = calendar;
186186

187187
touchCurrentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
@@ -219,8 +219,8 @@ class Calendar extends Framework7Class {
219219
`translate3d(${isH ? currentTranslate : 0}%, ${isH ? 0 : currentTranslate}%, 0)`,
220220
);
221221
}
222-
function handleTouchEnd() {
223-
if (!isTouched || !isMoved) {
222+
function handleTouchEnd(e) {
223+
if (!isTouched || !isMoved || !e.isTrusted) {
224224
isTouched = false;
225225
isMoved = false;
226226
return;

src/core/components/card/card.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ const CardExpandable = {
280280
let isH;
281281
let $cardScrollableEl;
282282
function onTouchStart(e) {
283-
if (!$(e.target).closest($cardEl).length) return;
283+
if (!$(e.target).closest($cardEl).length || !e.isTrusted) return;
284284
if (!$cardEl.hasClass('card-opened')) return;
285285
$cardScrollableEl = $cardEl.find(cardParams.scrollableEl);
286286

@@ -301,7 +301,7 @@ const CardExpandable = {
301301
isH = false;
302302
}
303303
function onTouchMove(e) {
304-
if (!isTouched) return;
304+
if (!isTouched || !e.isTrusted) return;
305305
touchEndX = e.targetTouches[0].pageX;
306306
touchEndY = e.targetTouches[0].pageY;
307307
if (typeof isScrolling === 'undefined') {
@@ -351,8 +351,8 @@ const CardExpandable = {
351351
);
352352
}
353353
}
354-
function onTouchEnd() {
355-
if (!isTouched || !isMoved) return;
354+
function onTouchEnd(e) {
355+
if (!isTouched || !isMoved || !e.isTrusted) return;
356356
isTouched = false;
357357
isMoved = false;
358358
if (device.ios) {

src/core/components/popup/popup-class.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class Popup extends Modal {
137137
let $pushEl;
138138

139139
function handleTouchStart(e) {
140-
if (isTouched || !allowSwipeToClose || !popup.params.swipeToClose) return;
140+
if (isTouched || !allowSwipeToClose || !popup.params.swipeToClose || !e.isTrusted) return;
141141
if (
142142
popup.params.swipeHandler &&
143143
$(e.target).closest(popup.params.swipeHandler).length === 0
@@ -157,7 +157,7 @@ class Popup extends Modal {
157157
}
158158
}
159159
function handleTouchMove(e) {
160-
if (!isTouched) return;
160+
if (!isTouched || !e.isTrusted) return;
161161
currentTouch = {
162162
x: e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX,
163163
y: e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY,
@@ -256,7 +256,8 @@ class Popup extends Modal {
256256
}
257257
$el.transition(0).transform(`translate3d(0,${-touchesDiff}px,0)`);
258258
}
259-
function handleTouchEnd() {
259+
function handleTouchEnd(e) {
260+
if (!e.isTrusted) return;
260261
isTouched = false;
261262
if (!isMoved) {
262263
return;

src/core/components/pull-to-refresh/pull-to-refresh-class.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class PullToRefresh extends Framework7Class {
122122
}
123123

124124
function handleTouchStart(e) {
125+
if (!e.isTrusted) return;
125126
if (isTouched) {
126127
if (device.os === 'android') {
127128
if ('targetTouches' in e && e.targetTouches.length > 1) return;
@@ -147,7 +148,7 @@ class PullToRefresh extends Framework7Class {
147148
}
148149

149150
function handleTouchMove(e) {
150-
if (!isTouched) return;
151+
if (!isTouched || !e.isTrusted) return;
151152
let pageX;
152153
let pageY;
153154
let touch;
@@ -327,6 +328,8 @@ class PullToRefresh extends Framework7Class {
327328
}
328329
}
329330
function handleTouchEnd(e) {
331+
if (!e.isTrusted) return;
332+
330333
if (e.type === 'touchend' && e.changedTouches && e.changedTouches.length > 0 && touchId) {
331334
if (e.changedTouches[0].identifier !== touchId) {
332335
isTouched = false;

src/core/components/sheet/sheet-class.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class Sheet extends Modal {
170170
let sheetPageContentOffsetHeight;
171171

172172
function handleTouchStart(e) {
173-
if (isTouched || !(sheet.params.swipeToClose || sheet.params.swipeToStep)) return;
173+
if (isTouched || !(sheet.params.swipeToClose || sheet.params.swipeToStep) || !e.isTrusted)
174+
return;
174175
if (
175176
sheet.params.swipeHandler &&
176177
$(e.target).closest(sheet.params.swipeHandler).length === 0
@@ -191,7 +192,7 @@ class Sheet extends Modal {
191192
}
192193
}
193194
function handleTouchMove(e) {
194-
if (!isTouched) return;
195+
if (!isTouched || !e.isTrusted) return;
195196
currentTouch = {
196197
x: e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX,
197198
y: e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY,

src/core/modules/router/swipe-back.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ function SwipeBack(r) {
344344
}
345345

346346
function handleTouchStart(e) {
347+
if (!e.isTrusted) return;
347348
const swipeBackEnabled = params[`${app.theme}SwipeBack`];
348349
if (
349350
!allowViewTouchMove ||
@@ -369,6 +370,7 @@ function SwipeBack(r) {
369370
dynamicNavbar = router.dynamicNavbar;
370371
}
371372
function handleTouchMove(e) {
373+
if (!e.isTrusted) return;
372374
if (!isTouched) return;
373375
const pageX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
374376
const pageY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
@@ -505,7 +507,8 @@ function SwipeBack(r) {
505507

506508
setAnimatableNavElements({ progress: percentage });
507509
}
508-
function handleTouchEnd() {
510+
function handleTouchEnd(e) {
511+
if (!e.isTrusted) return;
509512
app.preventSwipePanelBySwipeBack = false;
510513
if (!isTouched || !isMoved) {
511514
isTouched = false;

src/core/modules/touch/touch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ function initTouch() {
202202
let touchmoveActivableEl = null;
203203

204204
function handleTouchStart(e) {
205+
if (!e.isTrusted) return true;
205206
isMoved = false;
206207
tapHoldFired = false;
207208
preventClick = false;
@@ -249,6 +250,7 @@ function initTouch() {
249250
return true;
250251
}
251252
function handleTouchMove(e) {
253+
if (!e.isTrusted) return;
252254
let touch;
253255
let distance;
254256
let shouldRemoveActive = true;
@@ -329,6 +331,7 @@ function initTouch() {
329331
}
330332
}
331333
function handleTouchEnd(e) {
334+
if (!e.isTrusted) return true;
332335
isScrolling = undefined;
333336
isSegmentedStrong = false;
334337
segmentedStrongEl = null;

0 commit comments

Comments
 (0)