<div class="widget">
    <div class="widget-header">
      <div class="title">
        <span class="fs1" aria-hidden="true" data-icon="&#xe092;"></span> A4 - Insecure Direct Object References
      </div>
    </div>
    <div class="widget-body">
      <div id="accordion1" class="accordion no-margin">
        <div class="accordion-group">
          <div class="accordion-heading">
            <a href="#collapseOne" data-parent="#accordion1" data-toggle="collapse" class="accordion-toggle">
              <i class="icon-info icon-white">
              </i>
              Description
            </a>
          </div>
          <div class="accordion-body in collapse" id="collapseOne" style="height: auto;">
            <div class="accordion-inner">
              <p class="desc">
	Applications frequently use the actual name or key of an object when generating web pages. Applications don’t always verify the user is authorized for the target object. This results in an insecure direct object reference flaw. Testers can easily manipulate parameter values to detect such flaws. Code analysis quickly shows whether authorization is properly verified.
	 		  </p>
            </div>
          </div>
        </div>
        <div class="accordion-group">
          <div class="accordion-heading">
            <a href="#collapseTwo" data-parent="#accordion1" data-toggle="collapse" class="accordion-toggle">
              <i class="icon-bug icon-white">
              </i>
              Bug
            </a>
          </div>
          <div class="accordion-body collapse" id="collapseTwo" style="height: 0px;">
            <div class="accordion-inner">
              <p class="desc">
				Within the app/controllers/work_info_controller.rb file the follow code can be found:
	 		  </p>
	 		  <pre class="ruby">
				<%= %q{
				 class WorkInfoController < ApplicationController

				  def index
				    @user = User.find_by_user_id(params[:user_id])
				    if !(@user)
				      flash[:error] = "Sorry, no user with that user id exists"
				      redirect_to home_dashboard_index_path
				    end
				  end

				end 
				} %>
			  </pre>
			  <p class="desc">
				Instead of using the current_user object which, takes the user ID value from the user's session and is normally resilient against tampering, the user ID is pulled from the request parameter (user id in the RESTful URL). Additionally, even in the session, User IDs should be sufficiently random and the sessions stored in a persistent manner (ActiveRcord) versus using the Base64 encoded / HMAC validation session schema.
			  </p>	
            </div>
          </div>
        </div>
        <div class="accordion-group">
          <div class="accordion-heading">
            <a href="#collapseThree" data-parent="#accordion1" data-toggle="collapse" class="accordion-toggle">
              <i class="icon-lightning icon-white">
              </i>
              Solution
            </a>
          </div>
          <div class="accordion-body collapse" id="collapseThree" style="height: 0px;">
            <div class="accordion-inner">
              <p><b>Insecure Direct Object Reference - ATTACK</b></p>
 			  <p class="desc">
				 Navigate to the work info page, observe your user ID in the URL /users/<%= "<:user id>"%>/work_info.
				 Now change it to someone else's user ID.<br/><br/> Example - /users/2/work_info
	          </p>	
			  <p><b>Insecure Direct Object Reference - SOLUTION</b></p>
			  <p class="desc">
				The easiest way to fix this is to reference the current_user object. Also, it might make sense to not disclose any more sensitive information than necessary (re: error message).
	          </p>
			  <pre class="ruby">
				  def index
				    <span style="background-color:yellow">@user = current_user</span>
				    if !(@user) || @user.admin 
				      <span style="background-color:yellow">flash[:error] = "Apologies, looks like something went wrong"</span>
				      redirect_to home_dashboard_index_path
				    end
				  end
			  </pre>	 
            </div>
          </div>
        </div>
      	<div class="accordion-group">
          <div class="accordion-heading">
            <a  style="background-color: rgb(181, 121, 158)" href="#collapseFour" data-parent="#accordion1" data-toggle="collapse" class="accordion-toggle">
              <i class="icon-aid icon-white">
              </i>
              Hint
            </a>
          </div>
          <div class="accordion-body collapse" id="collapseFour" style="height: 0px;">
            <div class="accordion-inner">
              Hmmm, that's a lot of info under work info, hope that is secure
            </div>
          </div>
        </div>
	</div>
    </div>
  </div>