Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script security #271

Closed
wants to merge 8 commits into from
Closed

Conversation

selvanair
Copy link
Collaborator

@selvanair selvanair commented Jul 3, 2018

Ref: issue #270

See individual commit messages for details. Here is a summary.

  1. Enforce --script-security 1 but allow other legal values (0 to 3) or -1 to mean do not override the value in the config file
  2. Use a sha1 hash of the file to detect changes and revert the setting to the default
  3. A helper patch to easily handle user preferences for password save (needed for next commit)
  4. Add a dialog for setting the preferred script-security value. Also move some config-specific preferences such as save password to this dialog.

capture

  1. Add a checkbox to Settings->General dialog for enabling a global kill-switch for this feature. I was reluctant to add this but it will be missed by users who know what they are doing.

@selvanair
Copy link
Collaborator Author

My tests show this could be very annoying if scripts cause a fatal error when script-security is overridden. So we should consider this only if we can merge something like the patch I proposed for OpenVPN core: patch-395

@selvanair
Copy link
Collaborator Author

My tests show this could be very annoying if scripts cause a fatal error when script-security is overridden. So we should consider this only if we can merge something like the patch I proposed for OpenVPN core: patch-395

As discussed in openvpn-devel the fatal error seems to be the right thing to do so this could be merged without needing any changes to the core.

Anyone ready to test this patch?

Copy link

@TinCanTech TinCanTech left a comment

Choose a reason for hiding this comment

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

"Do not override script security (unsafe)" tested on W7 appears to work as expect.
(other tests to follow)

@TinCanTech
Copy link

TinCanTech commented Nov 25, 2018

With regard to the script security drop down box, this is not intuitive.
I recommend the drop down box list the numeric value of the setting.
eg:

0. No external commands (Very restrictive, may cause config to malfunction)
1. Built in commands only (Recommended)
2. All scripts (Unsafe)
3. All scripts and access to passwords (Very unsafe)
4. Use config file settings (Extremely unsafe)

I understand 4 is technically -1 but users are not going to understand that.

@TinCanTech
Copy link

TinCanTech commented Nov 25, 2018

I think that an extra manual "Warning" dialogue should also be considered for any setting above 1.
eg:

Warning: This setting is unsafe
Only use it if you understand the risks. See https://...
Please confirm: [Yes] [Cancel]

@selvanair
Copy link
Collaborator Author

Not convinced of the value of including a numerical number as these options do not really correspond to the number in the code (eg., there is no "use config file option" in the core).

The reason for the recommended setting at the top is that is the one selected by default and the best option. But agreed that probably we should re-order at least the rest -- whatever users will find convenient is fine with me.

By the way -- "use config file setting" is a valid option and potentially "extremely unsafe" at the same time: in the end, if the setting the GUI imposes does not match what is in config, the user is very likely going to get a FATAL error -- recall the discussion with Steffan which led to keeping the FATAL error when config wants to run a script but we override it in the GUI.

@TinCanTech
Copy link

TinCanTech commented Nov 25, 2018

Only with regard to the drop down list with a numeric, does the default option have to be the first on the list ? (I mean, is that required by the windows widget behind it or can the list appear numerically ordered but select 1 by default)
Perhaps a Radio selector instead ? (FYI: this is only feedback as a user)

@TinCanTech
Copy link

TinCanTech commented Nov 25, 2018

Not convinced of the value of including a numerical number as these options do not really correspond to the number in the code (eg., there is no "use config file option" in the core).

They do correspond, other than the "use Config file" option (which can be made clear in the GUI). Also, that they do correspond reinforces the core values ;-)

Copy link

@TinCanTech TinCanTech left a comment

Choose a reason for hiding this comment

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

Implement hash functions to enable tracking config file changes; Tested on W7, appears to work as expected. If config file is changed then script security is reset to default.

Copy link

@TinCanTech TinCanTech left a comment

Choose a reason for hiding this comment

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

Force script-security to SSEC_BUILT_IN by default; tested on W7, apppears to work as expect. Config file is locked while in use. If config is changed then script security is reset to default.

@TinCanTech
Copy link

All my tests completed with expected results.

Other than the list being out of logical order (which I presume can be corrected) and the possible change to a more appropriate gadget for that list (perhaps an up/down slider or something), I could not find any way to subvert script-security.

@selvanair
Copy link
Collaborator Author

This implementation needs a fix. If the user has limited privileges and the config is in the system-wide location, adding the --script-security option from the GUI will cause interactive service to wrongly reject the connection attempt as not authorized.

Options: for configs is in system-wide location, do not enforce a safe script security OR white-list "--script-security" as an option that any user can override. I prefer the latter as on Windows admins are often lay users who could unwittingly install insecure configs in the central location.

@selvanair
Copy link
Collaborator Author

I'm in the process of updating this PR like this:

Minimize the dialog about script security setting to just two options: (i) built-in commands only (recommended) and (ii) Use config file setting (potentially unsafe).

The rationale being the purpose of this patch is to force a safe setting unless the user explicitly authorizes to use the value in the config file. The drop-down menu is not for choosing all possible values of script-security --- config file is the place for that. Choices inconsistent with the config is only going to cause an error at runtime.

@cron2
Copy link
Contributor

cron2 commented Feb 10, 2019 via email

@cron2
Copy link
Contributor

cron2 commented Feb 10, 2019 via email

The setting is persisted in the registry as
HKCU\OpenVPN-GUI\config-name\script_security (DWORD)
with possible values 0 to 3 that has the same meaning
as described in  OpenVPN man page or -1 to mean do not
override the option (i.e, any value in the config file
will be effective).

The setting is reverted to default if the file changes
(tracked by a digest of the file). This feature is not
effective until the next commit where the digest function
is implemented.

The config file is locked against writes when a connection
is active. This ensures that if/when the file is re-read
by OpenVPN for a SIGHUP restart the contents have not
changed.

If no value is found in the registry the setting defaults
to 1 (SSEC_BUILT_IN).

TODO: add a dialog to edit the setting

Signed-off-by: Selva Nair <[email protected]>
- Use a SHA1 hash of the config file to detect file changes
and revert the script-security setting to default.

Signed-off-by: Selva Nair <[email protected]>
Currently user preference to save password is implicitly set
to true if a saved password is found in the registry. This makes
it difficult to toggle the save password flag from a dialog if
no previously saved password exists. Instead explicitly save
the preference.

This change helps implementation of the config-specific preferences
dialog (next commit). No user-visible changes.

Signed-off-by: Selva Nair <[email protected]>
- Add a connection-specific dialog with
  - options to override in the config file
    (currently only script-security)
  - check boxes for saving credentials or clearing
    saved ones.
  - stubs for "save username" and change the config
    display name are added (not enabled).

Accessible via tray->config-name->Options popup menu

The clear-saved-passwords menu item is removed as that
functionality is moved to this dialog.

Signed-off-by: Selva Nair <[email protected]>
- Add a check box to the Settings->General dialog to toggle
  o.disable_ssec_override

Signed-off-by: Selva Nair <[email protected]>
If error is due to script security over-ridden by us, reword
the message to a localizable string that points the user
to the config specific script-security setting.

Signed-off-by: Selva Nair <[email protected]>
- copy from the English rc file as is (need translation).

Signed-off-by: Selva Nair <[email protected]>
@selvanair
Copy link
Collaborator Author

selvanair commented Feb 12, 2019

Rebased to master with some changes:

  1. script-security setting in the menu reduced to two choices: "use config file setting (unsafe)" or "built-in scripts only (recommended)" and defaults to the latter as before.

  2. Added a commit that saves the last fatal error from OpenVPN and appends it to the message box shown when a connection fails. In case of script error if the setting is overridden by the GUI the message is reworded as a localizable string that defaults to:

External scripts are disabled for this connection as a security measure. If you must allow such scripts, open the connection specific "Options" menu and select to use config-file setting for "Allow script execution". Note that this is potentially unsafe unless you trust the origin of this connection profile.

For this to work properly OpenVPN requires patch 684 (https://patchwork.openvpn.net/patch/684/).

With this, when script security is set by the GUI failure shows up as

conn-failed-1

Else if the config file itself has script security < 2 the error shows as

conn-failed-2

The reason line is appended by this commit.

@selvanair
Copy link
Collaborator Author

selvanair commented Feb 20, 2019

The more I test this, the more I dislike it. Running a config with a script is no longer easy:

TLDR: there is a question at the end.

  1. Start with a config that has "--up xxx.bat", but no --script-security. Connection fails and GUI shows a message that points the user to the config-specific options menu

  2. User goes to options menu and chooses "Use config file setting (unsafe)" and tries to connect again

  3. Connection fails with an error saying --script-security >= 2 is required

  4. A few who manage to figure out the reason for that may edit the config, add --script-security 2 and try to connect again

  5. Connection fails with the GUI showing a message about safe script-security enforced and points the user to the Options menu

  6. Most give up at that point. A few patient ones go to the Options menu and once again revert the allow script execution to "use config file setting" and try to connect again.
    This time the connection succeeds.

Eventually everyone discovers the global "do not override script-security" option and enables that and happily tunnels ever after, oblivious of scripts infiltrating their configs.

How can we make this less frustrating and still safe?

and parse the error msg from OpenVPN proposed
in patch OpenVPN#688 (patchwork)

(to be squashed with previous commit c7462ab)

Signed-off-by: Selva Nair <[email protected]>
@selvanair
Copy link
Collaborator Author

Amended the last commit to match the proposed error message from OpenVPN in patch #688

@cron2
Copy link
Contributor

cron2 commented Feb 28, 2019 via email

@selvanair
Copy link
Collaborator Author

Parsing the config is in my TODO as its more generally useful.

I guess the fundamental problem is requiring settings in two different places to match one of which automatically changes in some non-intuitive ways. So, how about always set script-security from the GUI? That is, allow the user to choose all valid script-security settings from the GUI (as I had in a previous version, but no option to use the setting in the config file). And always pass --script-security on the command line. Then the user has to change this only in one place (in the GUI) and whatever is in the config file is never used. Unless globally disabled using the disable-script-security-override checkbox in the main settings.

Whenever the config file is edited we revert the script-security value back to 1. We could show that detail as a tool-tip for the dialog item and also could show a message when its reverted so that the user can edit the setting and then connect or go ahead as is.

Would such an improvement be worth the trouble..?

@cron2
Copy link
Contributor

cron2 commented Feb 28, 2019 via email

@selvanair
Copy link
Collaborator Author

Yeah, I assumed users have already graduated from OpenVPN U :) But anyway, overriding OpenVPN options can work effectively only if we expect some level of knowledge on part of the users. Unless we just want to ensure that we don't run any scripts without explicit consent from the user but do not care much whether that was informed consent or not..

Back to the drawing board, it seems.

@selvanair
Copy link
Collaborator Author

Based all the discussion this needs re-work and I haven't found time for it. For now withdrawing the PR to reduce clutter..

@selvanair selvanair closed this Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants