Skip to content

Commit

Permalink
LibGUI: Ensure that edit actions are disabled for password boxes
Browse files Browse the repository at this point in the history
This ensures that the user can't copy/cut text from password boxes which
would reveal the password. It also makes sure that the undo/redo actions
stay disabled because it's difficult to reason about what these do
exactly without being able to see the result.
  • Loading branch information
gunnarbeutner authored and linusg committed Aug 2, 2021
1 parent 9179d01 commit 17505ea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Userland/Libraries/LibGUI/TextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ PasswordBox::PasswordBox()
: TextBox()
{
set_substitution_code_point('*');
undo_action().set_enabled(false);
redo_action().set_enabled(false);
set_text_is_secret(true);
}

}
17 changes: 12 additions & 5 deletions Userland/Libraries/LibGUI/TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ void TextEditor::set_mode(const Mode mode)
m_mode = mode;
switch (mode) {
case Editable:
m_cut_action->set_enabled(has_selection());
m_cut_action->set_enabled(has_selection() && !text_is_secret());
m_delete_action->set_enabled(true);
m_paste_action->set_enabled(true);
set_accepts_emoji_input(true);
Expand All @@ -1502,8 +1502,8 @@ void TextEditor::set_mode(const Mode mode)

void TextEditor::did_update_selection()
{
m_cut_action->set_enabled(is_editable() && has_selection());
m_copy_action->set_enabled(has_selection());
m_cut_action->set_enabled(is_editable() && has_selection() && !text_is_secret());
m_copy_action->set_enabled(has_selection() && !text_is_secret());
if (on_selection_change)
on_selection_change();
if (is_wrapping_enabled()) {
Expand Down Expand Up @@ -1774,8 +1774,8 @@ void TextEditor::document_did_update_undo_stack()
return builder.to_string();
};

m_undo_action->set_enabled(can_undo());
m_redo_action->set_enabled(can_redo());
m_undo_action->set_enabled(can_undo() && !text_is_secret());
m_redo_action->set_enabled(can_redo() && !text_is_secret());

m_undo_action->set_text(make_action_text("&Undo", document().undo_stack().undo_action_text()));
m_redo_action->set_text(make_action_text("&Redo", document().undo_stack().redo_action_text()));
Expand Down Expand Up @@ -1980,4 +1980,11 @@ void TextEditor::redo()
document().redo();
}

void TextEditor::set_text_is_secret(bool text_is_secret)
{
m_text_is_secret = text_is_secret;
document_did_update_undo_stack();
did_update_selection();
}

}
5 changes: 5 additions & 0 deletions Userland/Libraries/LibGUI/TextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ class TextEditor

void delete_text_range(TextRange);

bool text_is_secret() const { return m_text_is_secret; }
void set_text_is_secret(bool text_is_secret);

protected:
explicit TextEditor(Type = Type::MultiLine);

Expand Down Expand Up @@ -387,6 +390,8 @@ class TextEditor
Gfx::IntPoint m_last_mousemove_position;

RefPtr<Gfx::Bitmap> m_icon;

bool m_text_is_secret { false };
};

}

0 comments on commit 17505ea

Please sign in to comment.