> For the complete documentation index, see [llms.txt](https://sumeru.gitbook.io/sumeru-cyber-security/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sumeru.gitbook.io/sumeru-cyber-security/common-vulnerabilites/insecure-direct-object-reference.md).

# 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/>
