TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Is isTrusted in DOM event reliable?

2 点作者 docuru大约 4 年前
I&#x27;m curious about prevent spam bot submitting forms (well, beside using captcha).<p>Some DOM events, for example MouseEvent, or FormEvent contains a boolean, read-only property `isTrusted`. Basically, to see if the action was performed by the user, we check if `event.isTrusted` is `true`.<p>From what I saw, there is one case to bypass a form `submit` event. When the form has a submit button (which does nothing). If I click the button through JavaScript, the button&#x27;s `click` event will have `isTrusted = false`. But when it bubble up, the form&#x27;s `submit` event will have `isTrusted` became `true`.<p>Is there any other case, isTrusted not reliable?

1 comment

phillipseamore大约 4 年前
The isTrusted flag won&#x27;t help out with that, it&#x27;s primarily an indicator that the event follows a user gesture and can escalate privileges (like playing audio). A spam bot will usually not be using an actual browser (or running JS) - and if it were it could easily say all events are trusted.
评论 #26523574 未加载