简体   繁体   English

为什么PasswordField在Vaadin中使用String而不是char []?

[英]Why PasswordField use String instead of char[] in Vaadin?

String is vulnerable for password values. 字符串容易受到密码值的影响。 I noticed that Vaadin PasswordField manipulates password as a String . 我注意到,Vaadin PasswordField操纵密码作为一个String

Following is default constructor of PasswordField , 以下是PasswordField默认构造函数,

public PasswordField() {
  setValue("");
}

My questions : 我的问题:

  • Is it safe to use PasswordField in Vaadin ? 在Vaadin中使用PasswordField是否安全?
  • What internal API does to assure the safety of the password ? 什么内部API可以确保密码的安全性?

TL;DR Vaadin PasswordField is a simple TextField . TL; DR Vaadin PasswordField是一个简单的TextField The input is hidden just in client-side, in server-side is transmitted in clear text. 输入隐藏在客户端,服务器端以明文形式传输。

Although you can use getConvertedValue() and setConvertedValue(Object value) for getting/setting the value in your own type. 虽然您可以使用getConvertedValue()setConvertedValue(Object value)来获取/设置您自己类型中的值。 Note that you have to set the setConverter(Converter<T,?> converter) before using it. 请注意,您必须在使用之前设置setConverter(Converter<T,?> converter)

Here you have an example of how to use properly the conversation: Creating your own converter for String - MyType conversion 这里有一个如何正确使用对话的示例: 为String创建自己的转换器 - MyType转换


FULL EXPLANATION 完整解释

Vaadin TextField , PasswordField and TextArea are all children of AbstractField<String> . Vaadin TextFieldPasswordFieldTextArea都是AbstractField<String>子代。

Vaadin Docs TextField

In detail: 详细地:

java.lang.Object
  |_ com.vaadin.server.AbstractClientConnector
       |_ com.vaadin.ui.AbstractComponent
            |_ com.vaadin.ui.AbstractField<java.lang.String>
                 |_ com.vaadin.ui.AbstractTextField

PasswordField works with String because of its parents, otherwise it should have implemented AbstractField<char[]> . PasswordField因其父项而使用String ,否则它应该已经实现了AbstractField<char[]>

In addition in the PasswordField section from Vaadin Docs says explicitly: 此外,在Vaadin DocsPasswordField部分中明确说明:

You should note that the PasswordField hides the input only from "over the shoulder" visual observation . 您应该注意, PasswordField 仅通过“肩膀”视觉观察隐藏输入。 Unless the server connection is encrypted with a secure connection, such as HTTPS, the input is transmitted in clear text and may be intercepted by anyone with low-level access to the network. 除非使用安全连接(例如HTTPS)对服务器连接进行加密,否则输入将以明文形式传输,并且可能会被对网络进行低级访问的任何人拦截。 Also phishing attacks that intercept the input in the browser may be possible by exploiting JavaScript execution security holes in the browser. 此外,通过利用浏览器中的JavaScript执行安全漏洞,可以拦截拦截浏览器中输入的网络钓鱼攻击。


Although AbstractField<T> has getConvertedValue() and setConvertedValue(Object value) which allow to get/set the value in the Object you prefer. 尽管 AbstractField<T>具有getConvertedValue()setConvertedValue(Object value) ,它们允许获取/设置您喜欢的Object的值。 Note that before using it you need to set setConverter(Converter<T,?> converter) . 请注意,在使用之前,您需要设置setConverter(Converter<T,?> converter)

Here you have an example of how to use properly the conversation: Creating your own converter for String - MyType conversion 这里有一个如何正确使用对话的示例: 为String创建自己的转换器 - MyType转换

In short from the example: 简而言之,这个例子:

Name is a simple POJO with firstName and lastName fields and their getter/setter. Name是一个带有firstNamelastName字段及其getter / setter的简单POJO

Converter class 转换器类

public class StringToNameConverter implements Converter<String, Name> {

    public Name convertToModel(String text, Locale locale) {
        String[] parts = text.split(" ");
        return new Name(parts[0], parts[1]);
    }

    public String convertToPresentation(Name name, Locale locale)
            throws ConversionException {
        return name.getFirstName() + " " + name.getLastName();
    }

    public Class<Name> getModelType() {
        return Name.class;
    }

    public Class<String> getPresentationType() {
        return String.class;
    }
}

Main class 主要课程

Name name = new Name("Rudolph", "Reindeer");
final TextField textField = new TextField("Name");
textField.setConverter(new StringToNameConverter());
textField.setConvertedValue(name);
addComponent(textField);
addComponent(new Button("Submit value", new ClickListener() {

    public void buttonClick(ClickEvent event) {
        Name name = (Name) textField.getConvertedValue();
    }

}));

Full source 完整来源

A little late to this party, but I'd like to add my 2 cents to what's already been discussed. 这个派对有点晚了,但我想把我的2美分加到已讨论的内容上。

It may be purely confort and code reuse, as PasswordField just extends AbstractTextField on the BE side which is basically an AbstractField<String> so all the value manipulation logic, event handling, etc is already there. 它可能纯粹是confort和代码重用,因为PasswordField只是在BE端扩展了AbstractTextField ,它基本上是一个AbstractField<String>所以所有的值操作逻辑,事件处理等都已存在。

Otherwise one would probably have to implement an AbstractField<char[]> and copy-paste pretty much everything from AbstractTextField just for this. 否则,可能必须实现一个AbstractField<char[]>并为此从AbstractTextField复制粘贴几乎所有东西。 Or to generify AbstractTextField or something similar... 或者生成AbstractTextField或类似的东西......

Either way, as already stated, an attacker would require access to the server to dump the memory, case in which you may have bigger problems, be it from outside or inside the organisation (there surely are cases in which own employees have done harm for some reasons) :-) 无论哪种方式,如前所述,攻击者都需要访问服务器以转储内存,在这种情况下,您可能会遇到更大的问题,无论是来自外部还是内部(当然,有些情况下,自己的员工已经造成了伤害。一些原因):-)

Regarding the FE, the VPasswordField counterpart creates an input of type password , and the security concerns in respect to the the FE-BE communication have already been discussed in Paolo Forgia's answer. 关于FE, VPasswordField对应方创建了一个类型为password的输入 ,并且已经在Paolo Forgia的答案中讨论了有关FE-BE通信的安全问题。

When vaadin codes runs in your web browser it is not in a JVM anymore, so using String is ok in this case. 当vaadin代码在您的Web浏览器中运行时,它不再位于JVM中,因此在这种情况下使用String是正常的。 The password will be stored as Java String in the server side, so in order to access that password String, an attacker has to access your server. 密码将作为Java String存储在服务器端,因此为了访问该密码String,攻击者必须访问您的服务器。

You should be looking at how that password field is handled in the generated javascript. 您应该查看在生成的javascript中如何处理该密码字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM