Skip to content
Business logic Disclosed report Intermediate

Changeable model ids on vanilla update can lead to severely bad side-effects

Rails allows a model's primary key to be changed through a normal update call when an 'id' parameter is passed in, and the author argues developers commonly leave 'id' in permitted parameters for nested resources. An attacker could set the id to a very large value, which on databases like Postgres can cause new record creation to fail with a duplicate key error, effectively blocking new content.

zachaysan Follow

Originally disclosed on HackerOne

  • Disclosed after 9 months

Proof of concept

User.find(1).update!(id: 1701)

But strong params!

Disagree. There are cases where less experienced users will allow "id" as a param for a subnested resource and then copy and past that code into that subnested resource's own controller, forgetting to remove the "id".

I consider this bug extremely severe since it is a very common pattern in most Rails JSON APIs and by setting the id to the maximum value may lead to the database to refuse to create new records OR in better databases like Postgres, an attacker can continue to stay just ahead of of the id sequence which will issue this error:

DETAIL: Key (id)=(1701) already exists.

This effectively stops any new content from being created with a very small number of attackers.

I have also tried to think of a way that a user could gain access to information with this, but I think that it would have to be in a very weird way. For example a multiple associations table where both tables save their associations to each other then one of them gets deleted. Too unlikely to be a major concern.

Proposed solution:

Make a special flag or special method for updating a model with a model id, but by default ignore "id" as a param. The reason I say "ignore" and not "raise exception" is that it is more convenient to not have to strip ids out of everything.

The original report as published on HackerOne, by zachaysan. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the framework permits the primary key attribute to be mass-assigned through update calls, so an 'id' parameter is written to the record rather than being ignored.

Impact

An attacker could set ids to very large values and, on databases like Postgres, keep just ahead of the id sequence so that new record creation fails, potentially stopping new content from being created.

What the attacker needed

Attacker can submit an id parameter; developer permits id in strong params

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Every database record has a unique number called an id that identifies it. In the Ruby on Rails framework, a normal update call can change that id if the developer forgets to block the 'id' field, and an attacker who sets it to a huge number can make the database refuse to create new records because it thinks the next id is already taken.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Ruby on Rails

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.