|
| 1 | +<!DOCTYPE qhelp PUBLIC |
| 2 | +"-//Semmle//qhelp//EN" |
| 3 | +"qhelp.dtd"> |
| 4 | +<qhelp> |
| 5 | + |
| 6 | + <overview> |
| 7 | + |
| 8 | + <p> |
| 9 | + |
| 10 | + Applications are constrained by how many resources they can make use |
| 11 | + of. Failing to respect these constraints may cause the application to |
| 12 | + be unresponsive or crash. It is therefore problematic if attackers |
| 13 | + can control the sizes or lifetimes of allocated objects. |
| 14 | + |
| 15 | + </p> |
| 16 | + |
| 17 | + </overview> |
| 18 | + |
| 19 | + <recommendation> |
| 20 | + |
| 21 | + <p> |
| 22 | + |
| 23 | + Ensure that attackers can not control object sizes and their |
| 24 | + lifetimes. If object sizes and lifetimes must be controlled by |
| 25 | + external parties, ensure you restrict the object sizes and lifetimes so that |
| 26 | + they are within acceptable ranges. |
| 27 | + |
| 28 | + </p> |
| 29 | + |
| 30 | + </recommendation> |
| 31 | + |
| 32 | + <example> |
| 33 | + |
| 34 | + <p> |
| 35 | + |
| 36 | + The following example allocates a buffer with a user-controlled |
| 37 | + size. |
| 38 | + |
| 39 | + </p> |
| 40 | + |
| 41 | + <sample src="examples/ResourceExhaustion_buffer.js" /> |
| 42 | + |
| 43 | + <p> |
| 44 | + |
| 45 | + This is problematic since an attacker can choose a size |
| 46 | + that makes the application run out of memory. Even worse, in older |
| 47 | + versions of Node.js, this could leak confidential memory. |
| 48 | + |
| 49 | + To prevent such attacks, limit the buffer size: |
| 50 | + |
| 51 | + </p> |
| 52 | + |
| 53 | + <sample src="examples/ResourceExhaustion_buffer_fixed.js" /> |
| 54 | + |
| 55 | + </example> |
| 56 | + |
| 57 | + <example> |
| 58 | + |
| 59 | + <p> |
| 60 | + |
| 61 | + As another example, consider an application that allocates an |
| 62 | + array with a user-controlled size, and then fills it with values: |
| 63 | + |
| 64 | + </p> |
| 65 | + |
| 66 | + <sample src="examples/ResourceExhaustion_array.js" /> |
| 67 | + |
| 68 | + <p> |
| 69 | + The allocation of the array itself is not problematic since arrays are |
| 70 | + allocated sparsely, but the subsequent filling of the array will take |
| 71 | + a long time, causing the application to be unresponsive, or even run |
| 72 | + out of memory. |
| 73 | + |
| 74 | + Again, a limit on the size will prevent the attack: |
| 75 | + |
| 76 | + </p> |
| 77 | + |
| 78 | + <sample src="examples/ResourceExhaustion_array_fixed.js" /> |
| 79 | + |
| 80 | + </example> |
| 81 | + |
| 82 | + <example> |
| 83 | + |
| 84 | + <p> |
| 85 | + |
| 86 | + Finally, the following example lets a user choose a delay after |
| 87 | + which a function is executed: |
| 88 | + |
| 89 | + </p> |
| 90 | + |
| 91 | + <sample src="examples/ResourceExhaustion_timeout.js" /> |
| 92 | + |
| 93 | + <p> |
| 94 | + |
| 95 | + This is problematic because a large delay essentially makes the |
| 96 | + application wait indefinitely before executing the function. Repeated |
| 97 | + registrations of such delays will therefore use up all of the memory |
| 98 | + in the application. |
| 99 | + |
| 100 | + Again, a limit on the delay will prevent the attack: |
| 101 | + |
| 102 | + </p> |
| 103 | + |
| 104 | + <sample src="examples/ResourceExhaustion_timeout_fixed.js" /> |
| 105 | + |
| 106 | + |
| 107 | + </example> |
| 108 | + |
| 109 | + <references> |
| 110 | + |
| 111 | + </references> |
| 112 | + |
| 113 | +</qhelp> |
0 commit comments