使用 Firebase 时如何安全地显示用户值?
How do you display user values safely when using Firebase?
我目前正在建立一个使用 Firebase Auth 作为其身份验证系统的网站。当我阅读有关 getting information from a user's profile 的文档时,我看到了这段文字。
Be careful when setting (and later displaying) potentially user-facing UI values like displayName and photoURL. The API does not filter the values to prevent potential XSS-type attacks.
我很好奇如何安全地显示用户的显示名称以防止 XSS 类型的攻击?
由于用户可以在其配置文件的 displayName
和 photoURL
值中插入任何内容,因此请务必始终将这些值视为潜在危险,不要将它们与您的代码。
如果您直接将值插入 client-side 应用程序代码中的 DOM/HTML,最好的方法是通过 属性 之类的 textContent
将自动编码任何 non-text 值。
与 server-side 代码类似,您可以使用平台的 HTML 编码功能,例如 this one for .NET.
有关这方面的更多信息,请参阅:
- Is it safe to display user input as input values without sanitization?
- Show HTML user input, security issue
我目前正在建立一个使用 Firebase Auth 作为其身份验证系统的网站。当我阅读有关 getting information from a user's profile 的文档时,我看到了这段文字。
Be careful when setting (and later displaying) potentially user-facing UI values like displayName and photoURL. The API does not filter the values to prevent potential XSS-type attacks.
我很好奇如何安全地显示用户的显示名称以防止 XSS 类型的攻击?
由于用户可以在其配置文件的 displayName
和 photoURL
值中插入任何内容,因此请务必始终将这些值视为潜在危险,不要将它们与您的代码。
如果您直接将值插入 client-side 应用程序代码中的 DOM/HTML,最好的方法是通过 属性 之类的 textContent
将自动编码任何 non-text 值。
与 server-side 代码类似,您可以使用平台的 HTML 编码功能,例如 this one for .NET.
有关这方面的更多信息,请参阅:
- Is it safe to display user input as input values without sanitization?
- Show HTML user input, security issue