ArticleslgStudy

computer science

Mass-assignment protection

Mass-assignment protection is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Mass-assignment protection rather than just read about it. In short: In the computing world, where software frameworks make life of developer easier, there are problems associated with it which the developer does not intend. Software frameworks use object-relational mapping (ORM) tool or active record pattern for converting data of different types and if the software framework does not have a strong mechanism to protect the fields of a class (the types of data), then it becomes easil…

Key takeaways

  • Mass-assignment protection belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Mass-assignment protection to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Mass-assignment protection from memory before moving on to harder problems.

Reference excerpt

In the computing world, where software frameworks make life of developer easier, there are problems associated with it which the developer does not intend. Software frameworks use object-relational mapping (ORM) tool or active record pattern for converting data of different types and if the software framework does not have a strong mechanism to protect the fields of a class (the types of data), then it becomes easily exploitable by the attackers. These frameworks allow developers to bind parameters with HTTP and manipulate the data externally. The HTTP request that is generated carries the parameters that is used to create or manipulate objects in the application program.

The phrase mass assignment or overposting refers to assigning values to multiple attributes in a single go. It is a feature available in frameworks like Ruby on Rails that allows the modifications of multiple object attributes at once using modified URL. For example, This Mass Assignment saves substantial amount of work for developers as they need not set each value individually.

Threats In Mass Assignment, a malicious agent can attack and manipulate the data in various ways. It can send the tags which can make him assign various permissions which would otherwise be forbidden. For example, a database schema has a table "users" having field "admin" which specifies if corresponding user is admin or not. Malicious agent can easily send the value for this field to the server through HTTP request and mark himself as an admin. This is called Mass assignment vulnerability. It explores the security breaches that can be done using mass assignment. GitHub got hacked in 2012 by exploiting mass assignment feature. Homakov who attacked GitHub gained private access to Rails by replacing his SSH with SSH key of one of the members of Rails GitHub.

Protection

ASP.NET Core In ASP.NET Core use the Bind attribute.

Ruby We can perform some changes in the active record models to ensure the protection of our data.

To use attr_protected: We specify the attributes which need to be protected. If the user tries mass assignment, then the user will get an error page which says Mass Assignment Security error and the attribute value will not be changed. This is also called blacklisting In this method, sometimes keeping track of all the attributes we want to protect is difficult. For example, in the code below, assign_project attribute is protected.This method optionally takes a role option using :as which enables to define multiple mass-assignment groupings. These attributes will have the :default role in case no role role is assigned. Here is an example which illustrates that assign_project will only be visible to admin. To use attr_accessible: We add attributes that are accessible to everyone and need not be protected. This is easier to manage as the attributes that can be mass-assigned can be explicitly selected. All others are considered as protected. This is sometimes referred to as whitelisting. To use Sanitize method: Another configuration which we can do to avoid mass assignment problems is called mass assignment sanitizer. This is a method called sanitize. This method filters the incoming requests and takes care that there should be no malicious tags. It only allows those tags that are whitelisted by the user. If the config config.active_record.mass_assignment_sanitizer is set to strict, it will raise ActiveModel::MassAssignmentSecurity::Error when mass assignment is not as intended. To use Require and Permit: These methods are used in Rails 4. These provide functionalities that check the incoming requests and parameters. Require method checks whether all the required parameters are present. If not, it throws error. Permit method checks whether a particular parameter is permitted to be passed in mass assignment. It returns the list of the permitted parameters. This is also referred to as strong parameters. Sometimes developer might forget adding attributes as accessible. So as to avoid this, recent versions of Rail has config setting config.active_record.whitelist_attributes = true" which creates blank white list of attributes and protects from Mass Assignment Vulnerability. Models still need to explicitly whitelist or blacklist accessible parameters.

References

Worked examples

Example 1 — a first encounter with Mass-assignment protection

Start with the simplest possible case. Write down what Mass-assignment protection claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Mass-assignment protection before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Mass-assignment protection ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Mass-assignment protection

In research
Mass-assignment protection appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Mass-assignment protection in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Mass-assignment protection is common in secondary-school and first-year university syllabi. It links to neighbouring topics Software development, so understanding it makes those chapters shorter.
In everyday life
Look for Mass-assignment protection outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Mass-assignment protection in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Mass-assignment protection means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Mass-assignment protection out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Mass-assignment protection in simple terms?

In the computing world, where software frameworks make life of developer easier, there are problems associated with it which the developer does not intend. Software frameworks use object-relational mapping (ORM) tool or active record pattern for converting data of different types and if the softwar…

Why does Mass-assignment protection matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Mass-assignment protection?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Mass-assignment protection.

Tags

  • Software development

Keep exploring