Code Review Steps and Methodologies
Code Review Steps and Methodologies
Table of contents
Introduction
Code review Checklist
Steps to perform on code review task
Tips for code review
Starting the Code review
Writing the vulnerability
Introduction:
Preforming a code review job needs some concentration and focus on the written environment
and understanding of its IO (input/output) and processing system, and before preforming a code
review task we should make some checks and ensure that the application/system we’re testing is
up and running.
Notice: Read about the language that you will test its code, if you don’t have an idea about
the language this will be difficult.
Notice: some clients give you the code and tell you to run it, also they may not have the
knowledge of how its developed, they may be uses outsource company to write the code, in this
situation, you have to build the application using the written IDE and report the build errors and
bugs to the project manager.
Never preform a code review job without having a working code, this is very dangerous, because
clients sometimes give us the wrong project and because for some reason we didn’t tested the
code in the IDE, and directly jumped into the code analysis we may have a problem latter on.
Moving on, we need to make a cheat-sheet that contain the following information, and this
information we’ll put them into the Code review Header area, so we can know what we did and
also the client as well:
Answering the above questions will help us understand the project and have an idea about what
tasks can be performed to well done this job.
Then we have to make a clone of the project(s) and build it, by us or by the responsible person in
the company.
Steps to perform on code review task:
1- Build the project
2- Understand the environment
3- Create a cheat sheet of the external libraries used
4- Run the code within its IDE
5- Insert break points on the main functions (if possible) to understand the data submitted
and parameters in the run time.
6- Create a new folder for the project, and copy all code files into it as the following:
6.A: Remove all dependencies in the project
6.B: Remove all DLL files and exclude all files that doesn’t have codes in it.
6.C Make sure the code files you copied have same structure as the original project.
Now we are good to go for the code analysis using manual and automated ways, but
there’s things to understand before jumping to the stage:
Tip Description
Review fewer than 400 lines of code at a time Developers should review no more than 200
to 400 lines of code (LOC) at a time. The
brain can only effectively process so much
information at a time; beyond 400 LOC, the
ability to find defects diminishes.
After we understand the application’s main entry point we start analyzing the calls that made to
initiate the application startup and analyze them one by one.
Then we start move into the first calls that made up by functions and procedures and what is the
return points, notice that some applications made up using MVC logics which is stand for
So, in the MVC app’s also catching the main entry point is deferent than other logic, in MVC we
start look at the main config area that links all controllers in the application, also the MVC logic
is not only made up for web applications, it also can be Desktop/mobile/ or IOT application.
For example, in the same .Net Framework we have also deferent environment and this can be
categorized as the project type:
Mobile applications / Web applications / IOT applications / Desktop applications /
When looking to the functions we track the return points and data presentation points, here’s an
example of an XSS in sample code written in PHP,
Index.HTML -> have a form that submit the username to another PHP page
Hello.PHP -> prints the input that coming from index.html page using post request,
As we can see in the code above its 100% vulnerable to XSS at least, here’s how:
If the user puts for example <script>alert (1) </script> this string will go to the PHP page and
then printed on the page without any filtration on it. And as we can see there’s no filtration or
protection made in the backend side before presenting this information.
So, the main idea of analyzing functions is to understand their behaviors and the way they
written, and what is their input, output and how this output made.
As we can see in the checklist above, we should make these steps on all the functions that the
code have manually and then write them into our report in case we found a vulnerability within
it.
Another important point is to also see how the code preforming data manipulation inside of the
memory, for example
Int number = ReadUserInput ();
The (number) variable has been defined as an integer, but what if we pass a number
9999999999999999 that’s more than the int32 in memory what will happen? also what if we
pass strings instead of passing numbers to the (number) variable also what will happen?
Asking the mentioned questions for the scenario above will let us check if there’s any restrictions
made before assigning the return value to (number) variable like if there’s some if statements or
Try Catch blocks that handle the malicious user input in the real time.
Language Tool
NodeJs https://github.com/ajinabraham/NodeJsScan
PHP https://sourceforge.net/projects/rips-scanner
Java http://findbugs.sourceforge.net/
.Net https://msdn.microsoft.com/en-
us/library/bb429476(v=vs.80).aspx
JavaScript http://jshint.com
C# https://codecrawler.codeplex.com/
.Net, Java, C/C++, http://www.scovetta.com/yasca.html
HTML, JavaScript,
ASP, ColdFusion,
PHP, COBOL
ASP, JSP, Perl, https://github.com/wireghoul/graudit
PHP, Python
C, C#, PHP, Java, https://github.com/CoolerVoid/codewarrior
Ruby, ASP,
JavaScript
Writing the vulnerability:
When you find a vulnerability, we should write the following in our report:
1- CWE
2- Vulnerability standard name
3- Vulnerability description
4- Vulnerability effect and risk
5- Line number and path for the Vulnerable code (screenshot is also fine).
6- How it can be fixed
7- Vulnerability type (Local/Remote).