Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Hardening new Roles system: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 1: Line 1:
New roles add great freedom when assigning rights to students. The problem might arise when students are assigned permission that allows adding of content that is not cleaned before display - such as editting Resources, adding activities, etc. They could then use any type of XSS attack to gain full administrative access without any restrictions.
New roles add great freedom when assigning capabilities to students. The problem might arise when students are assigned permission that allows adding of content that is not cleaned before display - such as editting Resources, adding activities, etc. They could then use any type of XSS attack to gain full administrative access quite easily.


==Proposed solution (updated with feedback and ideas from the rest)==
The solution has two parts: educate admins and teachers about the risks associated with each capability and optionally allow central management of risks.
===Risk bitmask in capabilities===
Add risk bitmap field to each capability. Each bit indicates presence of different risk associated with given capability.


====Basic risks====
==Risk bitmask in capabilities==
* access to private personal information - ex: backups with user details, non public information in profile (hidden email), etc.
Add risk bitmask field to each capability. Each bit indicates presence of different risk associated with given capability.
* missing XSS protection - entering of uncleaned content such as HTML with javascript or unprotected uploaded files
* dangerous global configuration changes - various settings that might render whole site unoperable, changing trust bitmaps
* some more if needed (can be added later)


====Implementation====
===Basic risks===
* add new LONGINT column ''riskbitmask'' to table ''capabilities''
* '''CAP_RISK_SPAM''' - user can add visible content to site, send messages to other users; originally protected by !isguest()
* '''CAP_RISK_PERSONAL''' - access to private personal information - ex: backups with user details, non public information in profile (hidden email), etc.; originally protected by isteacher()
* '''CAP_RISK_XSS''' - user can submit content that is not cleaned (both HTML with active content and unprotected files); originally protected by isteacher()
* '''CAP_RISK_ADMIN''' - user can change global configuration, actions are missing sanity checks, changing trust bitmasks
* ??
 
In default configuration Guest role should have only capabilities without risks, Student roles also SPAM, Teacher roles PERSONAL and XSS too. Admins have all capabilitites by default.
 
===Implementation===
* add new LONGINT column ''riskbitmask'' to table ''capabilities'' (DONE)
* define risks and assign them to capabilities in mod/xxx/db/access.php
* define risks and assign them to capabilities in mod/xxx/db/access.php
* link wiki pages with explanation to each risk from capabilities page
* link wiki pages with explanation to each risk from capabilities page
* allow risk based filtering of capabilities admin/roles/manage.php (optional)
* allow risk based filtering of capabilities admin/roles/manage.php (optional)


The user interface would be minimal, icons and maybe colors indicating each risk together with description links which we need anyway.
The user interface will be minimal, icons and maybe colors indicating each risk together with description links which we need anyway.
Developers would be deciding about the risks, the risk assignment would be hardcoded in access description file, no GUI needed.
Developers are deciding about the risks, the risk assignment would is hardcoded in access.php description file, no GUI needed.


====Benefits====
===Benefits===
# proper documentation of risks associated with capabilities, easy to explain
# proper documentation of risks associated with capabilities, easy to explain
# solid foundation for regular code audits (mainly XSS prevention and personal information disclosure)
# solid foundation for regular code audits (mainly XSS prevention and personal information disclosure)


===User trust bitmask===
==User trust bitmask==
Indicate what kind of trust each user has. Match the risk bitmap of capability and user trust bitmask in both has_capability() and require_capability()
Indicate what kind of trust each user has. Match the risk bitmask of capability and user trust bitmask in both has_capability() and require_capability().


====Implementation====
===Implementation===
* add new LONGINT column ''trustbitmask'' to ''user'' table
* add new LONGINT column ''trustbitmask'' to ''user'' table
* add capability ''moodle/site:managetrustbitmasks'' with dangerous global configuration risk
* add capability ''moodle/site:managetrustbitmasks'' with CAP_RISK_ADMIN risk
* add trust checks to has_capability() and require_capability()
* add trust checks to has_capability() and require_capability()
* add GUI
* add GUI
** preset trust bitmask for new users
** switch in global configuration to enable trust bitmask checking
** preseting of trust bitmask for new users
** changing of trust bitmasks
** changing of trust bitmasks
** add field to user/edit.php
** add trust bitmask setting to user/edit.php
** request trust level change form - something like new course request (optional)
** request trust level change form - something like new course request (optional)
* fix upgrade to assign trust bitmaps based on original teacher or administrator rights
* fix upgrade to assign trust bitmaps based on original teacher or administrator rights
* patch user import script and synchronizations (optional)
* patch user import script and synchronizations (optional)


====Benefits====
===Benefits===
# This part is optional and can be implemented later.
# This part is optional and can be implemented later.
# Trust manager or admin has full control over potentially dangerous capabilities - it is necessary for large sites (or connected sites in the future).  
# Trust manager or admin has full control over potentially dangerous capabilities - it is necessary for large sites (or connected sites in the future).  
# Trust bitmap mechanism can be turned off by single configuration switch (both GUI and checks) - needed for small insecure workshop sites.
# Trust bitmask mechanism can be turned off by single configuration switch (both GUI and checks) - needed for small insecure workshop sites.
# General protection against future bugs in role and capability management code.
# General protection against future bugs in role and capability framework or user errors when configuring roles.





Revision as of 21:05, 31 August 2006

New roles add great freedom when assigning capabilities to students. The problem might arise when students are assigned permission that allows adding of content that is not cleaned before display - such as editting Resources, adding activities, etc. They could then use any type of XSS attack to gain full administrative access quite easily.

The solution has two parts: educate admins and teachers about the risks associated with each capability and optionally allow central management of risks.

Risk bitmask in capabilities

Add risk bitmask field to each capability. Each bit indicates presence of different risk associated with given capability.

Basic risks

  • CAP_RISK_SPAM - user can add visible content to site, send messages to other users; originally protected by !isguest()
  • CAP_RISK_PERSONAL - access to private personal information - ex: backups with user details, non public information in profile (hidden email), etc.; originally protected by isteacher()
  • CAP_RISK_XSS - user can submit content that is not cleaned (both HTML with active content and unprotected files); originally protected by isteacher()
  • CAP_RISK_ADMIN - user can change global configuration, actions are missing sanity checks, changing trust bitmasks
  • ??

In default configuration Guest role should have only capabilities without risks, Student roles also SPAM, Teacher roles PERSONAL and XSS too. Admins have all capabilitites by default.

Implementation

  • add new LONGINT column riskbitmask to table capabilities (DONE)
  • define risks and assign them to capabilities in mod/xxx/db/access.php
  • link wiki pages with explanation to each risk from capabilities page
  • allow risk based filtering of capabilities admin/roles/manage.php (optional)

The user interface will be minimal, icons and maybe colors indicating each risk together with description links which we need anyway. Developers are deciding about the risks, the risk assignment would is hardcoded in access.php description file, no GUI needed.

Benefits

  1. proper documentation of risks associated with capabilities, easy to explain
  2. solid foundation for regular code audits (mainly XSS prevention and personal information disclosure)

User trust bitmask

Indicate what kind of trust each user has. Match the risk bitmask of capability and user trust bitmask in both has_capability() and require_capability().

Implementation

  • add new LONGINT column trustbitmask to user table
  • add capability moodle/site:managetrustbitmasks with CAP_RISK_ADMIN risk
  • add trust checks to has_capability() and require_capability()
  • add GUI
    • switch in global configuration to enable trust bitmask checking
    • preseting of trust bitmask for new users
    • changing of trust bitmasks
    • add trust bitmask setting to user/edit.php
    • request trust level change form - something like new course request (optional)
  • fix upgrade to assign trust bitmaps based on original teacher or administrator rights
  • patch user import script and synchronizations (optional)

Benefits

  1. This part is optional and can be implemented later.
  2. Trust manager or admin has full control over potentially dangerous capabilities - it is necessary for large sites (or connected sites in the future).
  3. Trust bitmask mechanism can be turned off by single configuration switch (both GUI and checks) - needed for small insecure workshop sites.
  4. General protection against future bugs in role and capability framework or user errors when configuring roles.


Note: trusttext moved to its own page at Trusttext cleaning bypass