# Insecure Direct Object Reference

## Introduction

Insecure Direct Object References(IDOR) occur when an application provides direct access to objects based on user-supplied input. As a result of this vulnerability, attackers can bypass authorization and access resources in the system directly, for example, database records or files.In simple words, it’s like getting sensitive information by just changing a few values in the parameter.

## How to Test

Hacker identifies web application using direct object reference(s) and requests verified information. Valid http request is executed and direct object reference entity is revealed.

![](/files/-M4Ty9OrAC9iPb-05HiO)

Direct object reference entity is manipulated and http request is performed again. Http request is performed without user verification and hacker is granted access to sensitive information.

![](/files/-M4TyBmpQXIFIdW4TkTA)

## How to Fix

* Enforce access control policies such that users cannot act outside of their intended permissions.
* Use hash function and use hashed values instead of normal numbers or strings.

Instead of this,

```
http://www.example.com/user.php?id=12
```

We can make it like this,

```
http://www.example.com/user.php?id=ea3eda3d3w2293
```

### PHP

```
$RandomAccountNumber = uniqid();
move_uploaded_file($ProfilePicTemp, "Content/" . $RandomAccountNumber);
```

### JAVA

```
Randomrandom=new Random();
Stringext = ".jpeg";
Filedir = new File("/home/pregzt");
Stringname = String.format("%s%s",System.currentTimeMillis(),random.nextInt(100000)+ext);
Filefile = new File(dir, name);
```

## References

1. ) <https://spanning.com/blog/insecure-direct-object-reference-web-based-application-security-part-6/>
2. &#x20;<https://codeburst.io/hunting-insecure-direct-object-reference-vulnerabilities-for-fun-and-profit-part-1-f338c6a52782>
3. <https://www.acunetix.com/blog/web-security-zone/what-are-insecure-direct-object-references/>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sumeru.gitbook.io/sumeru-cyber-security/common-vulnerabilites/insecure-direct-object-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
