forked from blackducksca-workflow-samples/automatic-fixpr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha7.html
More file actions
93 lines (88 loc) · 4.4 KB
/
a7.html
File metadata and controls
93 lines (88 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{% extends "./layout.html" %} {% block title %}A7-Missing Function Level Access Control{% endblock %} {% block content %}
<div class="row">
<div class="col-lg-12">
<div class="bs-example" style="margin-bottom: 40px;">
<span class="label label-danger">Exploitability: EASY</span>
<span class="label label-warning">Prevalence: COMMON</span>
<span class="label label-warning">Detectability: AVERAGE</span>
<span class="label label-warning">Technical Impact: MODERATE</span>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Description</h3>
</div>
<div class="panel-body">
Most web applications verify function level access rights before making that functionality visible in the UI. However, applications need to perform the same access control checks on the server when each function is accessed.
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Attack Mechanics</h3>
</div>
<div class="panel-body">
<p>If requests are not verified for access rights on server, attackers can forge requests in order to access functionality without proper authorization.</p>
<iframe width="560" height="315" src="//www.youtube.com/embed/ej6NCVd1Fo4?rel=0" frameborder="0" allowfullscreen></iframe>
<p>In the insecure demo application, this vulnerability exists in benefits module, which allows changing benefit start date for employees. The link to the benefits module is visible only to the admin user (user: admin, password: Admin_123). However, an attacker can access this module simply by logging in as any non-admin user and accessing <a id="benefits-menu-link" target="_blank" href="/benefits">benefits url</a> directly.
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">How Do I Prevent It?</h3>
</div>
<div class="panel-body">
Most web applications don’t display links and buttons to unauthorized functions, but this “presentation layer access control” doesn't actually provide protection. You must also implement checks in the controller or business logic.
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Source Code Examples</h3>
</div>
<div class="panel-body">
In vulnerable application, there is no authorization check for benefits related routes in
<code>routes/index.js</code>
<pre>
// Benefits Page
app.get("/benefits", isLoggedIn, benefitsHandler.displayBenefits);
app.post("/benefits", isLoggedIn, benefitsHandler.updateBenefits);
</pre>
<p>This can be fixed by adding a middleware to verify user's role:</p>
<pre>
// Benefits Page
app.get("/benefits", isLoggedIn, isAdmin, benefitsHandler.displayBenefits);
app.post("/benefits", isLoggedIn, isAdmin, benefitsHandler.updateBenefits);
</pre>
<p>To implement
<code>isAdmin</code>middleware, check if isAdmin flag is set for the logged in user in database.
<br/>For example, here is middleware function that can be added to
<code>routes\session.js</code>:</p>
<pre>
this.isAdminUserMiddleware = function(req, res, next) {
if (req.session.userId) {
userDAO.getUserById(req.session.userId, function(err, user) {
if(user && user.isAdmin) {
next();
} else {
return res.redirect("/login");
}
});
} else {
console.log("redirecting to login");
return res.redirect("/login");
}
};
</pre> It can be then made available in
<code>routes/index.js</code>router as:
<pre>
var SessionHandler = require("./session");
//Middleware to check if user has admin rights
var isAdmin = sessionHandler.isAdminUserMiddleware;
</pre>
</div>
</div>
</div>
</div>
{% endblock %}