Skip to content

Prompt the user before executing a command in a cmd:// URL#235

Merged
phoerious merged 1 commit intokeepassxreboot:developfrom
Throne3d:fix/51-prompt-before-cmd
Jan 28, 2017
Merged

Prompt the user before executing a command in a cmd:// URL#235
phoerious merged 1 commit intokeepassxreboot:developfrom
Throne3d:fix/51-prompt-before-cmd

Conversation

@Throne3d
Copy link
Copy Markdown
Contributor

Description

When the user selects to open a cmd:// URL, prompt them to ask, "Do you really want to execute the following command?"
(Does not have a "don't ask me anymore" option.)

Motivation and Context

Fixes #51.

Not having worked with Qt (ever) or C++ (much) in the past, I copied the code from the DatabaseWidget::deleteEntries method to prompt the user and adjusted it appropriately. Looking at an example on the Qt website, I realized you could insert HTML into the text for message boxes. I wasn't sure whether to use <br><br>, <br /><br />, or <p> to produce the linebreak effect, or whether I should just not attempt that at all and instead should embed it into the question (e.g. "Are you sure you want to run the command '%1'?"). I couldn't see any other instances of <br/?> or <p> in the code.

How Has This Been Tested?

I created two entries in a database – one with http://example.com as a URL and one instead with cmd://echo this could be a malicious command. Pressing the "Open URL" button in the context menu for the former opens the URL with no prompt, and with the latter produces the aforementioned message box. Clicking 'No' on the message box produces no output, and clicking 'Yes' produces 'this could be a malicious command' in the terminal.

Running the tests (DWITH_TESTS=ON and make test) produced no failures.

Screenshots (if appropriate):

https://i.gyazo.com/4fe418a1998c89a8fc901a936256643d.png

Types of changes

  • ✅ Bug fix (non-breaking change which fixes an issue)

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]

@phoerious
Copy link
Copy Markdown
Member

Not that your changes would break anything, but have you also tested with -DWITH_GUI_TESTS=ON? Those are usually the most important ones when you modify the UI.

@Throne3d
Copy link
Copy Markdown
Contributor Author

I did, yes. Forgot to mention.

result = MessageBox::question(
this, tr("Execute command?"),
tr("Do you really want to execute the following command?<br><br>%1")
.arg(urlString),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use urlString.toHtmlEscaped() here to prevent evaluation of HTML contents.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably also truncate it if it is too long. Otherwise the message box will be gigantic for very long commands.

Fixes #51.
(Does not have a "don't ask me anymore" option.)
@phoerious phoerious merged commit 0116d41 into keepassxreboot:develop Jan 28, 2017
@phoerious
Copy link
Copy Markdown
Member

Merged. Thanks for the patch!

@Throne3d Throne3d deleted the fix/51-prompt-before-cmd branch January 28, 2017 00:25
droidmonkey added a commit that referenced this pull request Jun 25, 2017
- Added YubiKey 2FA integration for unlocking databases [#127]
- Added TOTP support [#519]
- Added CSV import tool [#146, #490]
- Added KeePassXC CLI tool [#254]
- Added diceware password generator [#373]
- Added support for entry references [#370, #378]
- Added support for Twofish encryption [#167]
- Enabled DEP and ASLR for in-memory protection [#371]
- Enabled single instance mode [#510]
- Enabled portable mode [#645]
- Enabled database lock on screensaver and session lock [#545]
- Redesigned welcome screen with common features and recent databases [#292]
- Multiple updates to search behavior [#168, #213, #374, #471, #603, #654]
- Added auto-type fields {CLEARFIELD}, {SPACE}, {{}, {}} [#267, #427, #480]
- Fixed auto-type errors on Linux [#550]
- Prompt user prior to executing a cmd:// URL [#235]
- Entry attributes can be protected (hidden) [#220]
- Added extended ascii to password generator [#538]
- Added new database icon to toolbar [#289]
- Added context menu entry to empty recycle bin in databases [#520]
- Added "apply" button to entry and group edit windows [#624]
- Added macOS tray icon and enabled minimize on close [#583]
- Fixed issues with unclean shutdowns [#170, #580]
- Changed keyboard shortcut to create new database to CTRL+SHIFT+N [#515]
- Compare window title to entry URLs [#556]
- Implemented inline error messages [#162]
- Ignore group expansion and other minor changes when making database "dirty" [#464]
- Updated license and copyright information on souce files [#632]
- Added contributors list to about dialog [#629]
@phoerious phoerious added pr: new feature Pull request adds a new feature and removed new feature labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new feature Pull request adds a new feature security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ask user before executing "cmd://" URLs

2 participants