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

[14.0] [IMP] payroll: improve security #95

Closed
wants to merge 3 commits into from

Conversation

nimarosa
Copy link
Contributor

@nimarosa nimarosa commented Nov 8, 2022

Hello, this commit purpose is to improve security rules and add more restriction specially to editing python rules.

I will be making another tweaks to it in the following days, for now the changes are:

  • Created a new group, which is a hidden one (can only be activated in the user form, while being in developer mode and with a checkbox)
  • Users with this group, will be the only who can see the "python code" fields.
  • Other users, including the payroll manager, will see an error message it's shown in the following screenshot:

Screen Shot 2022-11-08 at 18 03 45

This is to make the user understand why he can't see the python code field, and don't believe it's a bug.
I have the intention of doing some tweaks to the other existing groups, so we can have very detailed and extensive security rules and groups, that could prevent the most any exploit of python safe_eval functionality. We will achieve that by limiting the roles, specially with all python related stuff, but not limited to.

Keep posted for more commits.

@OCA-git-bot
Copy link
Contributor

Hi @appstogrow,
some modules you are maintaining are being modified, check this out!

@norlinhenrik
Copy link
Contributor

Wow, I didn't see this UI tweak before.

The security setting says "Payroll: Allow editing python code in salary rules", but it also applies for reading. Either let the user read the code, or change the text, e.g. "Payroll: Show python code in salary rules" or "Payroll: Access to python code in salary rules".

I think the big pink box is too much of a warning. And "You are NOT allowed" might be discouraging to the user. I would replace all the text with a simple sentence:
"For security reasons, access to [or: editing] python code is restricted."
I don't mind including the last sentence: "If you think there is an error, please ask your system administrator." (add "please" and fix "adminsitrator").

@nimarosa
Copy link
Contributor Author

nimarosa commented Nov 9, 2022

@norlinhenrik

Wow, I didn't see this UI tweak before.

It's very good, I use it a lot to show messages. It can also be warning and info decoration.

The security setting says "Payroll: Allow editing python code in salary rules", but it also applies for reading. Either let the user read the code, or change the text, e.g. "Payroll: Show python code in salary rules" or "Payroll: Access to python code in salary rules".

Great, yes, I was thinking about changing the tests. So gonna accept the suggestion.

I think the big pink box is too much of a warning. And "You are NOT allowed" might be discouraging to the user. I would replace all the text with a simple sentence:

"For security reasons, access to [or: editing] python code is restricted."

I don't mind including the last sentence: "If you think there is an error, please ask your system administrator." (add "please" and fix "adminsitrator").

Great will make the changes. I can also make the box be yellow using the warning class. What do you think? It can be blue if I change it for info decoration.

@norlinhenrik
Copy link
Contributor

I think this is information, not a warning.

@norlinhenrik
Copy link
Contributor

@mtelahun Any opinions?

@nimarosa
Copy link
Contributor Author

nimarosa commented Nov 9, 2022

I think this is information, not a warning.

Okay so a info will be. Info box it's light blue. Will change it and post screenshot to make more easy to us to decide.

@mtelahun
Copy link
Contributor

mtelahun commented Nov 9, 2022 via email

@mtelahun
Copy link
Contributor

mtelahun commented Nov 9, 2022

@mtelahun Any opinions?

Hi @apps2grow ,
Please see my reply to @nimarosa. I appreciate the enthusiasm and the willingness to tackle this problem, but it will require careful consideration and the input of security people if we want to do it right.

@nimarosa
Copy link
Contributor Author

nimarosa commented Nov 9, 2022

@mtelahun yes, I know this don't fix the security problem which is safe_eval like. I think the only solution is get rid of it writing a new language like I stated in issue #94. It will be great to start discussing it there so we can start working in it in a new branch dedicated to build that feature.

About this PR, I understand your point of view but I really think limiting the access to only specific users allowed to write python is indeed good for reducing the risks.

Of course, an experimented hacker will always find the way to hack the system, because safe_eval is not safe at all. But this change will prevent a normal user at least to edit the rules to make harmful changes to the system. I see it not as a solution but a palliative.

For now, the only way to make safe_eval safe, is to trust user input, so I think limiting the functionality to only specific allowed users (and not the whole payroll manager group which can be composed by lot of users). With this change, you can specifically allow only trusted users to edit rules, or even you can allow it only for making changes and disallowing it after.

I know it's not really a security improvement but I think is positive to have it, even if it's requires more work from system administrator. The reality is rules don't change every day, so when all rules are created it's you will only change it if you need to adapt it to a new case o change something in it.

Also this continue allowing payroll managers to use and edit the standard functions in rules, it only limit python fields.

Finally, the PR is not finished but apart of hiding the field I'm planning of checking security group also in save and update methods, so if anyone manages to see the field without having the security group, it will not be allowed to save the form anyways.

Finally, I think it's not too much hassle to turn on a checkbox in the user to allow the user to edit the rule. How many people really in a payroll or hr department edit rules on daily basis? In my experience it's only a few people in the businesses that create and code rules, so it makes sense to not allow it to all "normal" users.

Like I said, it's not perfect and I accept more suggestions to this PR. But I think is necessary to implement something like this at least until we can replace safe_eval completely, but it's a large project and we should provide more security to payroll users.

@nimarosa
Copy link
Contributor Author

nimarosa commented Nov 9, 2022

The whole point of this is not fighting an experienced hacker. An experienced hacker will always found a way to crack the system and also not only in this module. We have other models in odoo that allow to write code with safe_eval.

The purpose of it is to reduce the amount of possible treats from normal users, or from someone in the business who know a bit of python and can exploit it.

Like I said, it didn't add security, but I think it reduce the chances that every payroll user could exploit it. For normal users, if they can't see it or edit it, they will desist in exploiting it. So I think it's more secure that allowing all payroll managers security group to access it.

@nimarosa nimarosa force-pushed the 14.0-add-security-rules branch from 48a5c65 to ba33fc2 Compare November 9, 2022 14:01
@nimarosa
Copy link
Contributor Author

nimarosa commented Nov 9, 2022

Changes in last commits:

  • Accepted suggestion by @norlinhenrik. Now the "error" is a informational one, and made some tweaks to make it look good.

Now it looks like this:

Screen Shot 2022-11-09 at 12 52 09

@norlinhenrik What do you think?

@nimarosa
Copy link
Contributor Author

/ocabot rebase

@OCA-git-bot
Copy link
Contributor

Congratulations, PR rebased to 14.0.

@OCA-git-bot OCA-git-bot force-pushed the 14.0-add-security-rules branch from 4c95860 to 23b62e0 Compare January 23, 2023 22:30
Copy link
Member

@mamcode mamcode left a comment

Choose a reason for hiding this comment

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

Please make squash of commits

@nimarosa nimarosa closed this Jun 7, 2023
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.

5 participants