<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Spsingh2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Spsingh2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Spsingh2"/>
	<updated>2026-05-08T21:15:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90800</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90800"/>
		<updated>2014-10-29T20:48:53Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Database Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%.&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90799</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90799"/>
		<updated>2014-10-29T20:48:29Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Database Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%.&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call generated the database driver by filtering the messages from the rails server. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
| -&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90796</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90796"/>
		<updated>2014-10-29T20:46:52Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Database Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%.&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call to each of the table entries. In the original code there were 625 data base select access generated for the leaderboard view. In the new code the number of select calls dropped to 111.&lt;br /&gt;
Shown below is the number of select calls generated per table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| No change&lt;br /&gt;
| -&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No change&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90791</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90791"/>
		<updated>2014-10-29T20:43:21Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Optimization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire type ( &amp;lt;code&amp;gt; Reviwed by Author, Reviewed by Teammates, Submitted Work and Reviewer &amp;lt;/code&amp;gt;), in each course. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable floatright&amp;quot;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; align=&amp;quot;center&amp;quot; | Expertiza Link&lt;br /&gt;
|-&lt;br /&gt;
| Refactored Instance&lt;br /&gt;
| http://152.1.13.181:3000&lt;br /&gt;
|-&lt;br /&gt;
| Original Instance&lt;br /&gt;
| http://152.1.13.181:3001&lt;br /&gt;
|}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex &amp;lt;code&amp;gt;(Complexity=142)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard.rb class gets all the assignments within all the courses taken by currently logged in user. It also fetches any independent assignments (not associated with any course), that the user has taken. Then, it fetches all the participants who have participated in the computed list of assignments and aggregates their scores based on the questionnaire type. Several questionnaire type is associated with a single assignment. e.g. Direwolf application has - ''Review Questionnaire'', ''Author Feedback Questionnaire'' and ''Teammate Review Questionnaire''.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to reduction in overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes in Model =&lt;br /&gt;
&lt;br /&gt;
Changes made in the methods of model &amp;lt;code&amp;gt; '''leaderboard.rb''' &amp;lt;/code&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes in Helper =&lt;br /&gt;
&lt;br /&gt;
Changes made in methods of Helper &amp;lt;code&amp;gt; leaderboard_helper.rb &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4 database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced by a |single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the original instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. &amp;lt;b&amp;gt;We changed the order in which the output is displayed to make it more coherent.&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Code complexity of original leaderboard implementation&lt;br /&gt;
! Code complexity of refactored leaderboard implementation&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_complexity.png|center|frame]]&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
| [[File:Refactored_Leaderboard_stats.png|center|frame]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%.&lt;br /&gt;
&lt;br /&gt;
== Database Optimization ==&lt;br /&gt;
We computed the number of data base &amp;quot;SELECT&amp;quot; call to each of the table entries.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Table Name&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
! Comment&lt;br /&gt;
|-&lt;br /&gt;
| roles&lt;br /&gt;
| 52&lt;br /&gt;
| 13&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| users&lt;br /&gt;
| 25&lt;br /&gt;
| 25&lt;br /&gt;
| No Change&lt;br /&gt;
|-&lt;br /&gt;
| participants&lt;br /&gt;
| 111&lt;br /&gt;
| 3&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignments&lt;br /&gt;
| 16&lt;br /&gt;
| 5&lt;br /&gt;
| Dummy&lt;br /&gt;
|-&lt;br /&gt;
| assignment_questionnaires&lt;br /&gt;
| 11&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized &lt;br /&gt;
|-&lt;br /&gt;
| questionnaires&lt;br /&gt;
| 311&lt;br /&gt;
| 0&lt;br /&gt;
| Optimized&lt;br /&gt;
|-&lt;br /&gt;
| score_caches&lt;br /&gt;
| 22&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| teams&lt;br /&gt;
| 11&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| teams_users&lt;br /&gt;
| 52&lt;br /&gt;
| 52&lt;br /&gt;
| -&lt;br /&gt;
| leaderboards&lt;br /&gt;
| 9&lt;br /&gt;
| 5&lt;br /&gt;
| Comment&lt;br /&gt;
|-&lt;br /&gt;
| courses&lt;br /&gt;
| 5&lt;br /&gt;
| 5&lt;br /&gt;
| No changes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;ref&amp;gt;&lt;br /&gt;
[https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time]&amp;lt;/ref&amp;gt; gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by almost 15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;b&amp;gt;Average&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;2.02&amp;lt;/b&amp;gt;&lt;br /&gt;
|&amp;lt;b&amp;gt;1.74&amp;lt;/b&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90699</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90699"/>
		<updated>2014-10-29T19:37:10Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes In Model (leaderboard.rb) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire types, in each courses. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes In Model (leaderboard.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was refactored on various aspects like reducing database calls drastically, removing redundant code computation, redundant data storage in complex group of hashes and series of conditional statements. We would like to mention that previously, the method had 10 database calls within loop and 1 outside loop. After refactoring, the new method has just 1 database call within loop and 3 outside loops. Also, the overall code complexity is reduced from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes In Helper (leaderboard_helper.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refactored Instance : http://152.1.13.181:3000 &amp;lt;br/&amp;gt;&lt;br /&gt;
Original Instance : http://152.1.13.181:3001&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the orignal instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. We changed the order in which the output is displayed to make it more coherent.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%.&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time] gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by 10-15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90697</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90697"/>
		<updated>2014-10-29T19:36:15Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes In Model (leaderboard.rb) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]'''&amp;lt;ref&amp;gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit E1467: Expertiza - Refactoring LeaderBoard model]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire types, in each courses. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
'''Classes involved:''' ''leaderboard.rb'' and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes In Model (leaderboard.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundant code computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing name and hard to follow logic.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes In Helper (leaderboard_helper.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refactored Instance : http://152.1.13.181:3000 &amp;lt;br/&amp;gt;&lt;br /&gt;
Original Instance : http://152.1.13.181:3001&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the orignal instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. We changed the order in which the output is displayed to make it more coherent.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%.&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en Page Load Time] gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by 10-15%.&lt;br /&gt;
&lt;br /&gt;
This table indicates time to load page in seconds&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| Iteration&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
|6&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
|7&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
|8&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
|9&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
|10&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90688</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90688"/>
		<updated>2014-10-29T19:32:22Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes In Model (leaderboard.rb) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t E1467: Expertiza - Refactoring LeaderBoard model]'''&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire types, in each courses. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes In Model (leaderboard.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally&lt;br /&gt;
by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes In Helper (leaderboard_helper.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refactored Instance : http://152.1.13.181:3000 &amp;lt;br/&amp;gt;&lt;br /&gt;
Original Instance : http://152.1.13.181:3001&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the orignal instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. We changed the order in which the output is displayed to make it more coherent.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
The refactoring process included reducing the database calls, loops and redundant storage and computation in all classes associated with Leaderboard functionality. While refactoring, the team has ensured to improve the readability of the code too by renaming ambiguous method and variable names and adding relevant comments to explain the objective of a code construct.&lt;br /&gt;
&lt;br /&gt;
== Code Optimization ==&lt;br /&gt;
&lt;br /&gt;
In the project description code complexity has been highlighted for several methods. [https://codeclimate.com/ Code Climate]&amp;lt;ref&amp;gt;[https://codeclimate.com/ Code Climate]&amp;lt;/ref&amp;gt; has been used to measure the code complexity of the current repository of Expertiza. After refactoring, we used the same tool i.e. Code Climate to measure the code complexity. Following is the snapshot of code complexity of &amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt; from Code Climate.&lt;br /&gt;
&lt;br /&gt;
[[File:CodeClimate_codecomplexity.png|center]]&lt;br /&gt;
&lt;br /&gt;
The report shows that all the 3 methods to be refactored have improved code complexity by over 50%.&lt;br /&gt;
&lt;br /&gt;
== Performance Optimization ==&lt;br /&gt;
&lt;br /&gt;
Google Chrome extension [https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en | Page Load Time] gives time to load a page.&lt;br /&gt;
We tried this extension to measure performance change after refactoring. We noticed that the time to load page reduced by 10-15%.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Original Version&lt;br /&gt;
! Refactored Version&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 2.08&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
| 2.02&lt;br /&gt;
| 1.66&lt;br /&gt;
|-&lt;br /&gt;
| 2.01&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.76&lt;br /&gt;
|-&lt;br /&gt;
| 1.93&lt;br /&gt;
| 1.72&lt;br /&gt;
|-&lt;br /&gt;
| 1.97&lt;br /&gt;
| 1.75&lt;br /&gt;
|-&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.74&lt;br /&gt;
|-&lt;br /&gt;
| 1.99&lt;br /&gt;
| 1.71&lt;br /&gt;
|-&lt;br /&gt;
| 2.12&lt;br /&gt;
| 1.80&lt;br /&gt;
|-&lt;br /&gt;
| 2.00&lt;br /&gt;
| 1.75&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90667</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90667"/>
		<updated>2014-10-29T19:17:16Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes In Model (leaderboard.rb) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
'''Project name: [https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t E1467: Expertiza - Refactoring LeaderBoard model]'''&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the ''&amp;quot;Leaderboard&amp;quot;'' functionality of the web application [https://github.com/expertiza/expertiza Expertiza]&amp;lt;ref&amp;gt;[https://github.com/expertiza/expertiza Expertiza]&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The leaderboard functionality is to show top 3 individual scorers in each questionnaire types, in each courses. The leaderboard also shows the current standing of the logged in user under personal achievements.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_controller.rb &amp;lt;/code&amp;gt; and associated views files. We have also refactored ambiguous variable and method names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and computation. We have refactored many files related to Leaderboard implementation leading to enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes In Model (leaderboard.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getIndependantAssignments &amp;lt;/code&amp;gt;&lt;br /&gt;
| Separate db call for each user assignment.&lt;br /&gt;
| Single db call with an array of assignment ids.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code. Appends each entry to the end of list&lt;br /&gt;
| Used concat to clarify that we are adding the independent and other assignments in courses. &lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; sortHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt;&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is &amp;lt;code&amp;gt; addScoreToResultantHash &amp;lt;/code&amp;gt;. As mentioned earlier, this is called internally&lt;br /&gt;
by &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is &amp;lt;code&amp;gt; getParticipantsScore &amp;lt;/code&amp;gt;. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes In Helper (leaderboard_helper.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; userIsInstructor &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; studentInWhichCourses &amp;lt;/code&amp;gt;&lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getTop3Leaderboards &amp;lt;/code&amp;gt;&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Refactored Instance : http://152.1.13.181:3000 &amp;lt;br/&amp;gt;&lt;br /&gt;
Original Instance : http://152.1.13.181:3001&lt;br /&gt;
&lt;br /&gt;
On VCL session there are 2 instances running. On &amp;lt;code&amp;gt; port 3001 &amp;lt;/code&amp;gt; the orignal instance is setup and on &amp;lt;code&amp;gt; port 3000 &amp;lt;/code&amp;gt; the refactored instance is setup.&lt;br /&gt;
In below images we have shown that the output after refactoring is same. We changed the order in which the output is displayed to make it more coherent.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of Original Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_personal_achievement_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method &amp;lt;code&amp;gt; getAssignmentMapping &amp;lt;/code&amp;gt;, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90601</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90601"/>
		<updated>2014-10-29T18:03:38Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Future Work */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
Expertiza - Refactoring LeaderBoard model&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes In Model (leaderboard.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes In Helper (leaderboard_helper.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| userIsInstructor &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| studentInWhichCourses &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| getTop3Leaderboards&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of non Refactored Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90600</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90600"/>
		<updated>2014-10-29T18:03:12Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes In Helper (leaderboard_helper.rb) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
Expertiza - Refactoring LeaderBoard model&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes In Model (leaderboard.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes In Helper (leaderboard_helper.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| userIsInstructor &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| studentInWhichCourses &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| getTop3Leaderboards&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of non Refactored Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90599</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90599"/>
		<updated>2014-10-29T18:00:36Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes In Model (leaderboard.rb) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
Expertiza - Refactoring LeaderBoard model&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Project Description=&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: &amp;lt;code&amp;gt; extractPersonalAchievements &amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt; method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor &amp;lt;code&amp;gt; addEntryToCSHash &amp;lt;/code&amp;gt; according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
=Existing Functionality=&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; getParticipantEntriesInAssignmentList(assignmentList) &amp;lt;/code&amp;gt;&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; extractPersonalAchievements(csHash, courseIdList, userId) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| &amp;lt;code&amp;gt; addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid) &amp;lt;/code&amp;gt;&lt;br /&gt;
| This method is called internally from &amp;lt;code&amp;gt; Leaderboard.getParticipantEntriesInAssignmentList &amp;lt;/code&amp;gt;. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
&amp;lt;code&amp;gt; Leaderboard.rb &amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt; Leaderboard_helper.rb &amp;lt;/code&amp;gt;. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
=Changes In Model (leaderboard.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from 67 to 39 .&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Changes In Helper (leaderboard_helper.rb) =&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| userIsInstructor &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| studentInWhichCourses &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| getTop3Leaderboards&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! View of Refactored Leaderboard&lt;br /&gt;
! View of non Refactored Leaderboard&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| [[File:Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
| [[File:Non_Refactored_Leaderboard_file.jpg|frame|left| ]]&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Optimization=&lt;br /&gt;
&lt;br /&gt;
=Future Work=&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
= References=&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90585</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90585"/>
		<updated>2014-10-29T17:35:59Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: &amp;lt;code&amp;gt;extractPersonalAchievements&amp;lt;/code&amp;gt;). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor ''addEntryToCSHash'' according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor ''getParticipantEntriesInAssignmentList'' method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor ''addEntryToCSHash'' according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| ''getParticipantEntriesInAssignmentList(assignmentList)''&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| ''extractPersonalAchievements(csHash, courseIdList, userId)''&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| ''addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)''&lt;br /&gt;
| This method is called internally from ''Leaderboard.getParticipantEntriesInAssignmentList''. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes In Model (leaderboard.rb) ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Changes In Helper (leaderboard_helper.rb) ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| userIsInstructor &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| studentInWhichCourses &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| getTop3Leaderboards&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
[[File:Refactored_Leaderboard_file.jpg| View of Refactored Leaderboard]]&lt;br /&gt;
[[File:Refactored_Personal_Achievement_file.jpg| View of Personal Achievement]]&lt;br /&gt;
&lt;br /&gt;
==Optimization==&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
== References==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90577</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90577"/>
		<updated>2014-10-29T17:33:20Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Expertiza - Refactoring LeaderBoard model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: ''extractPersonalAchievements''). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor ''addEntryToCSHash'' according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor ''getParticipantEntriesInAssignmentList'' method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor ''addEntryToCSHash'' according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| ''getParticipantEntriesInAssignmentList(assignmentList)''&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| ''extractPersonalAchievements(csHash, courseIdList, userId)''&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| ''addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)''&lt;br /&gt;
| This method is called internally from ''Leaderboard.getParticipantEntriesInAssignmentList''. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes In Model (leaderboard.rb) ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Changes In Helper (leaderboard_helper.rb) ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| userIsInstructor &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| studentInWhichCourses &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| getTop3Leaderboards&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
[[File:Refactored_Personal_Achievement_file.jpg|left|frame| View of Personal Achievement]]&lt;br /&gt;
[[File:Refactored_Leaderboard_file.jpg|right|frame| View of Refactored Leaderboard]]&lt;br /&gt;
&lt;br /&gt;
==Optimization==&lt;br /&gt;
&lt;br /&gt;
==Future Work==&lt;br /&gt;
There was a requirement in the project, that we should come up with an efficient way to search for participants based on assignment ids. However, upon investigation, we found that scores stored in table ScoreCache, gives us revieweeId which is either participantId or teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of participant and team with corresponding assignment. This is very useful while computing leaderboard.&lt;br /&gt;
&lt;br /&gt;
== References==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90561</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90561"/>
		<updated>2014-10-29T17:22:48Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Expertiza - Refactoring LeaderBoard model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: ''extractPersonalAchievements''). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor ''addEntryToCSHash'' according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor ''getParticipantEntriesInAssignmentList'' method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor ''addEntryToCSHash'' according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| ''getParticipantEntriesInAssignmentList(assignmentList)''&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| ''extractPersonalAchievements(csHash, courseIdList, userId)''&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| ''addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)''&lt;br /&gt;
| This method is called internally from ''Leaderboard.getParticipantEntriesInAssignmentList''. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes In Model (leaderboard.rb) ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Changes In Helper (leaderboard_helper.rb) ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| userIsInstructor &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| studentInWhichCourses &lt;br /&gt;
| Rewrote to reduce the number of database calls. &lt;br /&gt;
| This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| getTop3Leaderboards&lt;br /&gt;
| Dead code&lt;br /&gt;
| Removed.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
[[File:Refactored_Personal_Achievement_file.jpg||frame| View of Personal Achievement]]&lt;br /&gt;
[[File:Refactored_Leaderboard_file.jpg||frame| View of Refactored Leaderboard]]&lt;br /&gt;
&lt;br /&gt;
==Optimization==&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90553</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90553"/>
		<updated>2014-10-29T17:18:57Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:3%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the ranking of currently logged in user against total users associated with the same set of courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
| This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList. This method aggregates score of a user grouped by course id, further grouped by questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes In Model (leaderboard.rb) ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
[[File:Refactored_Leaderboard_file.jpg||frame|Build Status Page in CruiseControl &amp;lt;ref name=&amp;quot;cc&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. View of Refactored Leaderboard]]&lt;br /&gt;
&lt;br /&gt;
==Optimization==&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90549</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90549"/>
		<updated>2014-10-29T17:18:04Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.google.com/document/d/1FZCL9KWSdVNsX9BowuZ3gxbCOJoiWX-GVLctSZei3No/edit#heading=h.p92p30rar40t Writeup Page]&lt;br /&gt;
=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
| This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList. This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getIndependantAssignments&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| getParticipantEntriesInCourses&lt;br /&gt;
| Reduced the number of database calls within loop.&lt;br /&gt;
| Less complexity and runs faster.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| sortHash&lt;br /&gt;
| in place changes.&lt;br /&gt;
| Returns a new deep copy of the updated hash.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 4 '''''&lt;br /&gt;
| extractPersonalAchievements&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 5 '''''&lt;br /&gt;
| addEntryToCSHash&lt;br /&gt;
| Confusing code with extra data base calls.&lt;br /&gt;
| The new method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 6 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList&lt;br /&gt;
| This method was the most complex method in the class. &lt;br /&gt;
| The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
[[File:Refactored_Leaderboard_file.jpg||frame|Build Status Page in CruiseControl &amp;lt;ref name=&amp;quot;cc&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;. View of Refactored Leaderboard]]&lt;br /&gt;
&lt;br /&gt;
==Optimization==&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90531</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90531"/>
		<updated>2014-10-29T17:04:55Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Expertiza - Refactoring LeaderBoard model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
| This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList. This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
1. Leaderboard.rb&lt;br /&gt;
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are&lt;br /&gt;
refactored to reduce the database calls within loop. Database calls have huge impact on&lt;br /&gt;
overall complexity of the code and performance of the software.&lt;br /&gt;
○ sortHash : This method modified the input hash. We refactored it to not alter the input&lt;br /&gt;
hash object, but rather return a new deep copy of the updated hash object.&lt;br /&gt;
○ extractPersonalAchievements : This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
○ addEntryToCSHash : This method is refactored to reduce the redundant code. The new&lt;br /&gt;
method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
&lt;br /&gt;
○ getParticipantEntriesInAssignmentList : This method was the most complex method in&lt;br /&gt;
the class. The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
* Code complexity measurement is according to Code Climate&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
==Optimization==&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90530</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90530"/>
		<updated>2014-10-29T17:04:35Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Expertiza - Refactoring LeaderBoard model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
| This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList. This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
1. Leaderboard.rb&lt;br /&gt;
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are&lt;br /&gt;
refactored to reduce the database calls within loop. Database calls have huge impact on&lt;br /&gt;
overall complexity of the code and performance of the software.&lt;br /&gt;
○ sortHash : This method modified the input hash. We refactored it to not alter the input&lt;br /&gt;
hash object, but rather return a new deep copy of the updated hash object.&lt;br /&gt;
○ extractPersonalAchievements : This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
○ addEntryToCSHash : This method is refactored to reduce the redundant code. The new&lt;br /&gt;
method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
&lt;br /&gt;
○ getParticipantEntriesInAssignmentList : This method was the most complex method in&lt;br /&gt;
the class. The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
* Code complexity measurement is according to Code Climate&lt;br /&gt;
&lt;br /&gt;
==Testing===&lt;br /&gt;
==Optimization==&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90524</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90524"/>
		<updated>2014-10-29T16:53:21Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Existing Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:5%;&amp;quot;|Sr. No.&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Comment&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|''''' 1 '''''&lt;br /&gt;
| getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
|This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 2 '''''&lt;br /&gt;
| extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
| This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
|-&lt;br /&gt;
|''''' 3 '''''&lt;br /&gt;
| addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
| This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList. This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
1. Leaderboard.rb&lt;br /&gt;
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are&lt;br /&gt;
refactored to reduce the database calls within loop. Database calls have huge impact on&lt;br /&gt;
overall complexity of the code and performance of the software.&lt;br /&gt;
○ sortHash : This method modified the input hash. We refactored it to not alter the input&lt;br /&gt;
hash object, but rather return a new deep copy of the updated hash object.&lt;br /&gt;
○ extractPersonalAchievements : This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
○ addEntryToCSHash : This method is refactored to reduce the redundant code. The new&lt;br /&gt;
method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
&lt;br /&gt;
○ getParticipantEntriesInAssignmentList : This method was the most complex method in&lt;br /&gt;
the class. The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
* Code complexity measurement is according to Code Climate&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90519</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90519"/>
		<updated>2014-10-29T16:46:04Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Existing Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Functionality==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
&lt;br /&gt;
Leaderboard model has following 3 important methods:&lt;br /&gt;
&lt;br /&gt;
1. getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
○ This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
&lt;br /&gt;
2. extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
○ This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
&lt;br /&gt;
3. addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
○ This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList.&lt;br /&gt;
○ This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. &lt;br /&gt;
We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature.&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
1. Leaderboard.rb&lt;br /&gt;
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are&lt;br /&gt;
refactored to reduce the database calls within loop. Database calls have huge impact on&lt;br /&gt;
overall complexity of the code and performance of the software.&lt;br /&gt;
○ sortHash : This method modified the input hash. We refactored it to not alter the input&lt;br /&gt;
hash object, but rather return a new deep copy of the updated hash object.&lt;br /&gt;
○ extractPersonalAchievements : This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
○ addEntryToCSHash : This method is refactored to reduce the redundant code. The new&lt;br /&gt;
method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
&lt;br /&gt;
○ getParticipantEntriesInAssignmentList : This method was the most complex method in&lt;br /&gt;
the class. The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
* Code complexity measurement is according to Code Climate&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90517</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90517"/>
		<updated>2014-10-29T16:43:38Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
&lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Code==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
leaderboard model has following 3 important methods:&lt;br /&gt;
1. getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
○ This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
2. extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
○ This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
3. addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
○ This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList.&lt;br /&gt;
○ This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature. Following are some of the changes that we think are&lt;br /&gt;
sharing in readme file. For all the other changes, please visit our forked repository&lt;br /&gt;
(https://github.com/sanjeevs/expertiza/tree/rails4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
1. Leaderboard.rb&lt;br /&gt;
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are&lt;br /&gt;
refactored to reduce the database calls within loop. Database calls have huge impact on&lt;br /&gt;
overall complexity of the code and performance of the software.&lt;br /&gt;
○ sortHash : This method modified the input hash. We refactored it to not alter the input&lt;br /&gt;
hash object, but rather return a new deep copy of the updated hash object.&lt;br /&gt;
○ extractPersonalAchievements : This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
○ addEntryToCSHash : This method is refactored to reduce the redundant code. The new&lt;br /&gt;
method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
&lt;br /&gt;
○ getParticipantEntriesInAssignmentList : This method was the most complex method in&lt;br /&gt;
the class. The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
* Code complexity measurement is according to Code Climate&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90516</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90516"/>
		<updated>2014-10-29T16:43:01Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Project Description */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
1. Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
&lt;br /&gt;
2. Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
&lt;br /&gt;
3. Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
4. Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. &lt;br /&gt;
&lt;br /&gt;
5. Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
&lt;br /&gt;
6.Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
==Existing Code==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
leaderboard model has following 3 important methods:&lt;br /&gt;
1. getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
○ This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
2. extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
○ This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
3. addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
○ This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList.&lt;br /&gt;
○ This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature. Following are some of the changes that we think are&lt;br /&gt;
sharing in readme file. For all the other changes, please visit our forked repository&lt;br /&gt;
(https://github.com/sanjeevs/expertiza/tree/rails4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
1. Leaderboard.rb&lt;br /&gt;
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are&lt;br /&gt;
refactored to reduce the database calls within loop. Database calls have huge impact on&lt;br /&gt;
overall complexity of the code and performance of the software.&lt;br /&gt;
○ sortHash : This method modified the input hash. We refactored it to not alter the input&lt;br /&gt;
hash object, but rather return a new deep copy of the updated hash object.&lt;br /&gt;
○ extractPersonalAchievements : This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
○ addEntryToCSHash : This method is refactored to reduce the redundant code. The new&lt;br /&gt;
method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
&lt;br /&gt;
○ getParticipantEntriesInAssignmentList : This method was the most complex method in&lt;br /&gt;
the class. The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
* Code complexity measurement is according to Code Climate&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90513</id>
		<title>CSC/ECE 517 Fall 2014/OSS E1467 rsv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_E1467_rsv&amp;diff=90513"/>
		<updated>2014-10-29T16:31:01Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Expertiza - Refactoring LeaderBoard model=&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Our project is to refactor the code in the &amp;quot;Leaderboard&amp;quot; functionality of the web application Expertiza&amp;lt;ref name=&amp;quot;expertiza&amp;gt;''Expertiza'' http://wikis.lib.ncsu.edu/index.php/Expertiza&amp;lt;/ref&amp;gt;. The Expertiza project is a system to create reusable learning objects through peer review. The classes involved gets all the assignments in the course and all the participants in a course or in an assignment. The responsibility of the leaderboard module is to generate the top 3 individuals which is to be displayed as the leaderboard for the class and a personal leaderboard view to see a personal aggregated score.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
Classes involved: leaderboard.rb and associated other model and controllers classes. &lt;br /&gt;
What it does:  This class gets all the assignments in the course and all the participants in a course or in an assignment. It also caches all the scores of the participants in various assignments. Its responsible for calculating top 3 individuals which is to be displayed as the leaderboard for the class and generates a metric which aggregates peer review scores for all course assignments and then sorts individuals. Also it has a personal leaderboard to see a personal aggregated score. &lt;br /&gt;
What needs to be done:  &lt;br /&gt;
Refactor getParticipantEntriesInAssignmentList method. Its very complex (Complexity=142).&lt;br /&gt;
Seperate out computation of CS entries(metric) and refactor it to be more modular and elegant. You can even come up with a better metric to calculate an aggregate score for all peer reviews, metareviews(if any), teammate review, etc. Assign more weights to programming assignments. You will need to refactor other dependent classes. &lt;br /&gt;
Come up with an efficient way to search for participants based on assignment ids.&lt;br /&gt;
Refactor score hash for personal achievements. (Method: extractPersonalAchievements). Seperate out method which will rank individual personal achievements.&lt;br /&gt;
Refactor addEntryToCSHash according to your new metric method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Code==&lt;br /&gt;
Leaderboard class gets all the assignments within all the courses taken by currently logged in user. It&lt;br /&gt;
also fetches any independent assignments (not associated with any course), that the user has taken.&lt;br /&gt;
leaderboard model has following 3 important methods:&lt;br /&gt;
1. getParticipantEntriesInAssignmentList(assignmentList)&lt;br /&gt;
○ This method is responsible for calculating the leaderboard of all the participants associated&lt;br /&gt;
with assignments in given assignment list.&lt;br /&gt;
2. extractPersonalAchievements(csHash, courseIdList, userId)&lt;br /&gt;
○ This method is responsible for calculating personal aggregated score. It also calculates the&lt;br /&gt;
ranking of currently logged in user against total users associated with the same set of&lt;br /&gt;
courses as that of current user.&lt;br /&gt;
3. addEntryToCSHash(qtypeHash, qtype, userid, csEntry, courseid)&lt;br /&gt;
○ This method is called internally from Leaderboard.getParticipantEntriesInAssignmentList.&lt;br /&gt;
○ This method aggregates score of a user grouped by course id, further grouped by&lt;br /&gt;
questionnaire type.&lt;br /&gt;
In the OSS project, we have refactored these methods along with other smaller methods in&lt;br /&gt;
Leaderboard.rb, Leaderboard_helper.rb. We have also refactored ambiguous variable and method&lt;br /&gt;
names.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We have keenly focussed in reducing the database calls, loops and redundant storage and&lt;br /&gt;
computation. We have refactored many files related to Leaderboard implementation leading to&lt;br /&gt;
enhancement of overall complexity of the feature. Following are some of the changes that we think are&lt;br /&gt;
sharing in readme file. For all the other changes, please visit our forked repository&lt;br /&gt;
(https://github.com/sanjeevs/expertiza/tree/rails4)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Changes==&lt;br /&gt;
1. Leaderboard.rb&lt;br /&gt;
○ Methods like getIndependantAssignments and getParticipantEntriesInCourses are&lt;br /&gt;
refactored to reduce the database calls within loop. Database calls have huge impact on&lt;br /&gt;
overall complexity of the code and performance of the software.&lt;br /&gt;
○ sortHash : This method modified the input hash. We refactored it to not alter the input&lt;br /&gt;
hash object, but rather return a new deep copy of the updated hash object.&lt;br /&gt;
○ extractPersonalAchievements : This method is refactored to use only 1 database call&lt;br /&gt;
unlike several within the loop in its prior implementation. We have also removed redundantcode computation and made the logic easier to understand. The overall complexity of this&lt;br /&gt;
method is reduced from 72 to 35 *.&lt;br /&gt;
○ addEntryToCSHash : This method is refactored to reduce the redundant code. The new&lt;br /&gt;
method name is addScoreToResultantHash. As mentioned earlier, this is called internally&lt;br /&gt;
by getParticipantEntriesInAssignmentList. The complexity of this method is reduced from&lt;br /&gt;
67 to 39 *.&lt;br /&gt;
&lt;br /&gt;
○ getParticipantEntriesInAssignmentList : This method was the most complex method in&lt;br /&gt;
the class. The new refactored method name is getParticipantsScore. The method was&lt;br /&gt;
refactored on various aspects like reducing database calls drastically, removing redundant&lt;br /&gt;
code computation, redundant data storage in complex group of hashes and series of&lt;br /&gt;
conditional statements. We would like to mention that previously, the method had 10&lt;br /&gt;
database calls within loop and 1 outside loop. After refactoring, the new method has just 1&lt;br /&gt;
database call within loop and 3 outside loops. Also, the overall code complexity is reduced&lt;br /&gt;
from 142 to 64 *.&lt;br /&gt;
○ There was a requirement in the project, that we should come up with an efficient way to&lt;br /&gt;
search for participants based on assignment ids. However, upon investigation, we found&lt;br /&gt;
that scores stored in table ScoreCache, gives us revieweeId which is either participantId or&lt;br /&gt;
teamId. Therefore, we have a method getAssignmentMapping, which creates a mapping of&lt;br /&gt;
participant and team with corresponding assignment. This is very useful while computing&lt;br /&gt;
leaderboard.&lt;br /&gt;
2. Leaderboard_helper.rb&lt;br /&gt;
○ userIsInstructor : This method was refactored to reduce multiple database calls. 4&lt;br /&gt;
database calls was replaced by single call.&lt;br /&gt;
○ studentInWhichCourses : This method was refactored to reduce multiple database calls&lt;br /&gt;
and remove unnecessary loops. 1 database call outside and 1 within a loop was replaced&lt;br /&gt;
by a single call.&lt;br /&gt;
○ getTop3Leaderboards : This method is a dead code, not called from anywhere, therefore,&lt;br /&gt;
we have commented this for the moment.&lt;br /&gt;
There are several other changes in the views and controller which deal with renaming of the methods&lt;br /&gt;
and variables, adding proper comments etc and minor code refactoring. Please refer to our forked&lt;br /&gt;
github repository to view those changes.&lt;br /&gt;
Lastly, we would like to recommend the readers to test the leaderboard functionality by any user who&lt;br /&gt;
has participated in several assignments, some of them which is associated with any course and there&lt;br /&gt;
are other existing users who have participated in the same assignment. e.g. user480/password&lt;br /&gt;
* Code complexity measurement is according to Code Climate&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=88450</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=88450"/>
		<updated>2014-09-25T21:33:30Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Cookie Management */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
Web applications are very open and susceptible to many types of attacks. Many of these attacks can be carried out anonymously and constantly. A web application developer must be vigilant in understanding the threats that exist, and the proper techniques to mitigate them. &lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
===Improved Cookie Serializer(Rails 4.x) ===&lt;br /&gt;
Earlier versions of Rails had a bug where serializing the cookie hash could cause remote code execution. This could happen if the attacker got hold of the application secret. Version 4.1 added a smarter serializer that will '''not''' recreate complex objects besides Strings, Integers and other JSON data types. This also prevents the bad practice of placing more complex objects in the session that can’t be completely restored by the JSON serializer.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page. &lt;br /&gt;
&lt;br /&gt;
Injection can be a script, sql statement, ajax code or header injection. Though the root cause is poor programming, Rails provide various plug ins that allow the programmer to avoid it. &lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) &amp;lt;ref&amp;gt;https://www.acunetix.com/websitesecurity/xss/&amp;lt;/ref&amp;gt;====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. &amp;lt;ref&amp;gt;http://guides.rubyonrails.org/security.html&amp;lt;/ref&amp;gt; The sanitize_SQL method may be used to remove improper characters.&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
HTTP request headers have various fields that are user supplied and may be manipulated with more or less effort. Programmer need to escape these header fields and avoid building partial headers based on user input. Rails provide a rich api that can be used to create the headers in a secure fashion.&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 3.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 3: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following:&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token. Rails inserts this required security token that our site knows but other sites don't know. This is verified on the server. If the security token does not match then the session will be reset. &lt;br /&gt;
&lt;br /&gt;
Enable this in the application controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
protect_from_forgery&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using the followingn in applicatin controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.filter_parameters&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
In this section, we examine techniques to improve to the security of Rails web applications.&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/LTe/scanny Scanny] is and open source security scanner for Rails source code. It works by parsing individual Ruby files and looking for suspicious patterns in them. Scanny produces a security report after completion.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
There are a few unresolved issues in the current release of Rails. In this section, we examine and describe those concerns with instructions on methods to mitigate them.&lt;br /&gt;
&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86844</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86844"/>
		<updated>2014-09-19T16:27:32Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Unresolved Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page. &lt;br /&gt;
&lt;br /&gt;
Injection can be a script, sql statement, ajax code or header injection. Though the root cause is poor programming, Rails provide various plug ins that allow the programmer to avoid it. &lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
HTTP request headers have various fields that are user supplied and may be manipulated with more or less effort. Programmer need to escape these header fields and avoid building partial headers based on user input. Rails provide a rich api that can be used to create the headers in a secure fashion.&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 3.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 3: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token. Rails inserts this required security token that our site knows but other sites don't know. This is verified on the server. If the security token does not match then the session will be reset. &lt;br /&gt;
&lt;br /&gt;
Enable this in the application controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
protect_from_forgery&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using the followingn in applicatin controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.filter_parameters&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86843</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86843"/>
		<updated>2014-09-19T16:26:38Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* User Authentication */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page. &lt;br /&gt;
&lt;br /&gt;
Injection can be a script, sql statement, ajax code or header injection. Though the root cause is poor programming, Rails provide various plug ins that allow the programmer to avoid it. &lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
HTTP request headers have various fields that are user supplied and may be manipulated with more or less effort. Programmer need to escape these header fields and avoid building partial headers based on user input. Rails provide a rich api that can be used to create the headers in a secure fashion.&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 3.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 3: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token. Rails inserts this required security token that our site knows but other sites don't know. This is verified on the server. If the security token does not match then the session will be reset. &lt;br /&gt;
&lt;br /&gt;
Enable this in the application controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
protect_from_forgery&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using the followingn in applicatin controller.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.filter_parameters&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86842</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86842"/>
		<updated>2014-09-19T16:25:29Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Security Token */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page. &lt;br /&gt;
&lt;br /&gt;
Injection can be a script, sql statement, ajax code or header injection. Though the root cause is poor programming, Rails provide various plug ins that allow the programmer to avoid it. &lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
HTTP request headers have various fields that are user supplied and may be manipulated with more or less effort. Programmer need to escape these header fields and avoid building partial headers based on user input. Rails provide a rich api that can be used to create the headers in a secure fashion.&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 3.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 3: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token. Rails inserts this required security token that our site knows but other sites don't know. This is verified on the server. If the security token does not match then the session will be reset. &lt;br /&gt;
&lt;br /&gt;
Enable this in the application controller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
protect_from_forgery&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86841</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86841"/>
		<updated>2014-09-19T16:23:38Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Security Token */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page. &lt;br /&gt;
&lt;br /&gt;
Injection can be a script, sql statement, ajax code or header injection. Though the root cause is poor programming, Rails provide various plug ins that allow the programmer to avoid it. &lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
HTTP request headers have various fields that are user supplied and may be manipulated with more or less effort. Programmer need to escape these header fields and avoid building partial headers based on user input. Rails provide a rich api that can be used to create the headers in a secure fashion.&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 3.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 3: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token. Rails inserts this required security token that our site knows but other sites don't know. This is verified on the server.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86840</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86840"/>
		<updated>2014-09-19T16:22:00Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Cross Site Request Forgery (CSRF) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page. &lt;br /&gt;
&lt;br /&gt;
Injection can be a script, sql statement, ajax code or header injection. Though the root cause is poor programming, Rails provide various plug ins that allow the programmer to avoid it. &lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
HTTP request headers have various fields that are user supplied and may be manipulated with more or less effort. Programmer need to escape these header fields and avoid building partial headers based on user input. Rails provide a rich api that can be used to create the headers in a secure fashion.&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 3.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 3: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86839</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86839"/>
		<updated>2014-09-19T16:21:24Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Injection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page. &lt;br /&gt;
&lt;br /&gt;
Injection can be a script, sql statement, ajax code or header injection. Though the root cause is poor programming, Rails provide various plug ins that allow the programmer to avoid it. &lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
HTTP request headers have various fields that are user supplied and may be manipulated with more or less effort. Programmer need to escape these header fields and avoid building partial headers based on user input. Rails provide a rich api that can be used to create the headers in a secure fashion.&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 2.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 2: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86838</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86838"/>
		<updated>2014-09-19T16:14:04Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Injection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
The general form of XSS attack is show below in Figure2.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 2.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 2: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This provides the ability to store your sensitive tokens in an environment variable for better security. The ''secrets.yml'' file is also in .gitignore by default, which helps out unaware programmers from accidentally committing their key.&lt;br /&gt;
&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86695</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86695"/>
		<updated>2014-09-18T20:22:51Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Injection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
The general form of XSS attack is show below in Figure.&lt;br /&gt;
[[File:Xss.png|none]]&lt;br /&gt;
Figure2: XSS attack in progress&lt;br /&gt;
&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 2.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 2: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
In Rails applications up through version 4.0, a generated secret security token was created in ''config/initializers/secret_token.rb'' when creating a Rails application. This token was vulnerable to being left unsecured by developers, or accidentally getting committed to a version control system. An adversary who obtained the secret token could trivially exploit the web application.&lt;br /&gt;
&lt;br /&gt;
These concerns were alleviated in Ruby 4.1. The secret token file was replaced by a ''secrets.yml'' file in the config folder. &lt;br /&gt;
&lt;br /&gt;
'''secrets.yml:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
development:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
test:&lt;br /&gt;
  secret_key_base:&lt;br /&gt;
 &lt;br /&gt;
production:&lt;br /&gt;
  secret_key_base: &amp;lt;%= ENV[&amp;quot;SECRET_KEY_BASE&amp;quot;] %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file is in .gitignore by default, when helps out unaware programmers.&lt;br /&gt;
&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Xss.png&amp;diff=86692</id>
		<title>File:Xss.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Xss.png&amp;diff=86692"/>
		<updated>2014-09-18T20:20:31Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86688</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86688"/>
		<updated>2014-09-18T20:08:49Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 2.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 2: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
By default when starting a Rails server, it will bind to ''http://0.0.0.0:3000''. For a development environment, this is often unnecessary and only needs to bind to ''127.0.0.1''. Developers should use the ''--binding'' option to limit the interfaces to only those that are necessary.&lt;br /&gt;
&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
https://www.acunetix.com/websitesecurity/xss/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86682</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86682"/>
		<updated>2014-09-18T20:01:46Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Cross Site Request Forgery (CSRF) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 2.&lt;br /&gt;
[[File:My_csrf.png|none]]&lt;br /&gt;
Figure 2: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86681</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86681"/>
		<updated>2014-09-18T20:00:56Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Cross Site Request Forgery (CSRF) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;img src=“x”&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands. This is shown below in Figure 2.&lt;br /&gt;
[[File:My_csrf.png]]&lt;br /&gt;
Figure 2: CSRF attack&lt;br /&gt;
&lt;br /&gt;
To fix this the application needs to do the following.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
The default web server for a Rails application is [http://en.wikipedia.org/wiki/WEBrick WEBrick]. It is a simple open source server that is not often used in production, but has a potential security vulnerability if used in a live application. WEBrick returns a verbose security header which returns the full version number of both WEBrick and Ruby. &amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example HTTP Response:&amp;lt;ref&amp;gt;http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
# …&lt;br /&gt;
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This verbose message is unnecessary and provides too much information to a potential intruder. An adversary can easily scan many web applications looking for un-patched servers that may be exploited.&lt;br /&gt;
&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:My_csrf.png&amp;diff=86676</id>
		<title>File:My csrf.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:My_csrf.png&amp;diff=86676"/>
		<updated>2014-09-18T19:58:19Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86658</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86658"/>
		<updated>2014-09-18T19:39:51Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* SQL Injection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
'''Input to be sanitized''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Sanitized output:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
To protect the application from this potential vulnerability, you should be careful when processing any SQL query that contains user submitted data. The sanitize_SQL method may be used to remove improper characters. &lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
There are a number of different security analysis tools available for Ruby on Rails applications. &lt;br /&gt;
&lt;br /&gt;
*[http://brakemanscanner.org/docs/introduction/ Brakeman] is an open source, automated static-analysis scanner available for Rails developers. Brakeman scans the source code for misconfiguration, conformance to best practices, and other potential security issues.&lt;br /&gt;
&lt;br /&gt;
*[https://github.com/codesake/codesake-dawn Codesake::Dawn] is another open source scanner for Rails applications. It attempts to detect the MVC architecture of your application to properly check the code base. Codesake scans for XSS scripting and SQL injection vulnerabilities.&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86638</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86638"/>
		<updated>2014-09-18T18:49:17Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Security Enhancements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===SQL Injection===&lt;br /&gt;
It is possible that the attacker can manipulate web application parameters by influencing database queries.&lt;br /&gt;
Rails can  prevent such attacks by providing filters for special SQL characters which escapes ',' NULL character and line breaks.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86637</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86637"/>
		<updated>2014-09-18T18:48:45Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* User Authentication */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end. Rails 4 also introduces a multiline option for validates_format_of.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===SQL Injection===&lt;br /&gt;
It is possible that the attacker can manipulate web application parameters by influencing database queries.&lt;br /&gt;
Rails can  prevent such attacks by providing filters for special SQL characters which escapes ',' NULL character and line breaks.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86633</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86633"/>
		<updated>2014-09-18T18:42:41Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* User Security Policies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== Application Logic ==&lt;br /&gt;
There are certain common functionality that most applications need to implement. If these are not implemented correctly, then they can cause a security vulnerability. Rails provide plug ins that make the job easier to implement. Some common cases are discussed below.&lt;br /&gt;
&lt;br /&gt;
===User Authentication===&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end.&lt;br /&gt;
&lt;br /&gt;
===File Upload===&lt;br /&gt;
Many applications allow user to upload files. Use Rail plugin to handle unsafe file names and file upload.&lt;br /&gt;
&lt;br /&gt;
===SQL Injection===&lt;br /&gt;
It is possible that the attacker can manipulate web application parameters by influencing database queries.&lt;br /&gt;
Rails can  prevent such attacks by providing filters for special SQL characters which escapes ',' NULL character and line breaks.&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
Ruby provides api like &amp;quot;''system(command, parameters)'' which passes command line parameters safely.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86624</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86624"/>
		<updated>2014-09-18T17:49:05Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Redirection */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86623</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86623"/>
		<updated>2014-09-18T17:48:43Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* File Upload */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
==Redirection==&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86622</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86622"/>
		<updated>2014-09-18T17:47:27Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* User Security Policies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
==Redirection==&lt;br /&gt;
&lt;br /&gt;
==File Upload==&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
Most web applications have to deal with user authorization and authentication. Hence it is up to the programmer to implement it correctly. Rails provide built in &amp;quot;''has_secure_password'' feature that stores the password in encrypted manner.&lt;br /&gt;
*Brute Force Attack&lt;br /&gt;
** Good Password: Ensure that the user password are &amp;quot;random&amp;quot; enough. Rails make it easy to define requirements for the password field in the model.&lt;br /&gt;
** Implement CAPTCHAs:This is a challenge response test that determines that the response is not generated by a computer. Rails provide extensive API for implementing it.&lt;br /&gt;
*Logging:Rails should be configured to not put passwords into log files by using &amp;quot;''config.filter_parameters'' in application configuration.&lt;br /&gt;
*Anchor Regular Expressions:Ruby has extensive options that can be used to anchor it at the line beginning and line end.&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86581</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86581"/>
		<updated>2014-09-18T16:41:11Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Use SSL */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
''config.force_ssl = true&lt;br /&gt;
''&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
==Redirection==&lt;br /&gt;
&lt;br /&gt;
==File Upload==&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
===Password Protection===&lt;br /&gt;
====Good passwords ====&lt;br /&gt;
====Brute Force attack ====&lt;br /&gt;
====CAPTCHAs====&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86579</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86579"/>
		<updated>2014-09-18T16:40:40Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Timeout Cookies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Fast Timeout===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
==Redirection==&lt;br /&gt;
&lt;br /&gt;
==File Upload==&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
===Password Protection===&lt;br /&gt;
====Good passwords ====&lt;br /&gt;
====Brute Force attack ====&lt;br /&gt;
====CAPTCHAs====&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86577</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86577"/>
		<updated>2014-09-18T16:40:14Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Cookie Management */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.[[File:cookie_sniffing.png|none]]&lt;br /&gt;
Figure1: Packet Sniffing Attack&lt;br /&gt;
&lt;br /&gt;
To manage the cookies Rails provide several options to the programmer. &lt;br /&gt;
===Use SSL===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login.&lt;br /&gt;
&lt;br /&gt;
===Timeout Cookies===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value so that chances of attacker using a stale cookie is minimized.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
==Redirection==&lt;br /&gt;
&lt;br /&gt;
==File Upload==&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
===Password Protection===&lt;br /&gt;
====Good passwords ====&lt;br /&gt;
====Brute Force attack ====&lt;br /&gt;
====CAPTCHAs====&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86575</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86575"/>
		<updated>2014-09-18T16:34:46Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Cookie Management */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
More over since the data is stored on the client machine, programmers should not store sensitive data in cookies. &lt;br /&gt;
&lt;br /&gt;
The cookie is sent in the clear and so the easiest way for the attacker is to sniff the packets. This attack is shown below in Figure 1.&lt;br /&gt;
&lt;br /&gt;
[[File:cookie_sniffing.png|frame|Figure1: Sniffing Traffic]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Use SSL ===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login. This prevents &amp;quot;Session Fixation&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Timeout Cookies===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
==Redirection==&lt;br /&gt;
&lt;br /&gt;
==File Upload==&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
===Password Protection===&lt;br /&gt;
====Good passwords ====&lt;br /&gt;
====Brute Force attack ====&lt;br /&gt;
====CAPTCHAs====&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86574</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 23 ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_23_ss&amp;diff=86574"/>
		<updated>2014-09-18T16:21:16Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: /* Cookie Management */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= '''Security Features in Rails 4.x''' =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Web applications can be challenging for a developer to properly secure against threats. There are many attack vectors against web applications that must be carefully considered and mitigated. The developer must be responsible to understand these threats and take the necessary steps to secure the application and data.  A web application may be vulnerable due to misconfiguration, poorly written code, or through un-patched vulnerabilities. &lt;br /&gt;
&lt;br /&gt;
[http://rubyonrails.org/ Ruby on Rails], or just Rails, is a web application framework written in Ruby. It is a full-stack framework which attempts to make the development process easier and more accessible. This wiki aims to highlight all the security features in a Rails 4.x.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
= Threats Against Web Applications =&lt;br /&gt;
&lt;br /&gt;
==Cookie Management==&lt;br /&gt;
Cookies are used to maintain stateful sessions in HTTP. The cookies typically contain the user's session id which is used to identify the user. By stealing it, the attacker can use the application in the victim's name.&lt;br /&gt;
Hence programmers should not store sensitive data in cookies. &lt;br /&gt;
[[File:cookie_sniffing.png]]&lt;br /&gt;
The fix is&lt;br /&gt;
===Use SSL ===&lt;br /&gt;
SSL prevents the attacker from sniffing the cookie from the network.&lt;br /&gt;
config.force_ssl = true&lt;br /&gt;
&lt;br /&gt;
===New Session Identifier===&lt;br /&gt;
Configure Rails to issue a new session identifier and declare the old one invalid after a successful login. This prevents &amp;quot;Session Fixation&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
===Timeout Cookies===&lt;br /&gt;
Set the expiry time stamp of the cookie to a small value.&lt;br /&gt;
&lt;br /&gt;
==Injection ==&lt;br /&gt;
An attacker can inject client site executable code. When the victim renders it, it can steal the cookie, hijack the session and redirect the victim to a different page.&lt;br /&gt;
==== Cross Site Scripting (XSS) ====&lt;br /&gt;
&lt;br /&gt;
XSS is an attack where an adversary places client-side code in the web application, often through a valid method such as posting to a message board. This code is then viewed by other application users and executed by their client machines.&lt;br /&gt;
&lt;br /&gt;
This attack is mitigated by properly sanitizing any input to the application. &amp;lt;ref&amp;gt;https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/&amp;lt;/ref&amp;gt; The sanitize method may be used to strip improper code from user input. &lt;br /&gt;
&lt;br /&gt;
Input to be sanitized:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;%= sanitize '&amp;lt;img src=x onerror=prompt(1)&amp;gt;' %&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sanitized output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;img src=“x”&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SQL Injection ====&lt;br /&gt;
&lt;br /&gt;
SQL injection is a very common and serious vulnerability for many applications. The generalized concept is to pass carefully crafted input that will eventually get passed as parameters in a SQL statement. In July of 2014, Rails developers released version 4.1.3 in order to patch a serious vulnurability affecting applications using a PostgreSQL database system. &amp;lt;ref&amp;gt;http://www.computerworld.com/article/2489654/malware-vulnerabilities/ruby-on-rails-patches-tackle-sql-injection-vulnerabilities.html&amp;lt;/ref&amp;gt; This vulnerability allowed attackers to inject arbitrary SQL code into the affected Rails applications.&lt;br /&gt;
&lt;br /&gt;
Mitigation here.&lt;br /&gt;
&lt;br /&gt;
==== Ajax Injection ====&lt;br /&gt;
&lt;br /&gt;
==== Header Injection ====&lt;br /&gt;
&lt;br /&gt;
==Cross Site Request Forgery (CSRF)==&lt;br /&gt;
This attack method works by including malicious code or a link in a page that accesses a web application that the user is believed to have authenticated. If the session for that web application has not timed out, an attacker may execute unauthorized commands.&lt;br /&gt;
&lt;br /&gt;
===Security Token===&lt;br /&gt;
All non GET request should use a security token.&lt;br /&gt;
&lt;br /&gt;
==Redirection==&lt;br /&gt;
&lt;br /&gt;
==File Upload==&lt;br /&gt;
&lt;br /&gt;
== User Security Policies ==&lt;br /&gt;
===Password Protection===&lt;br /&gt;
====Good passwords ====&lt;br /&gt;
====Brute Force attack ====&lt;br /&gt;
====CAPTCHAs====&lt;br /&gt;
&lt;br /&gt;
= Security Enhancements =&lt;br /&gt;
==  CSRF via Leaky #match Routes ==&lt;br /&gt;
== Regular Expression Anchors in Format Validations ==&lt;br /&gt;
== Clickjacking ==&lt;br /&gt;
==  User-Readable Sessions ==&lt;br /&gt;
&lt;br /&gt;
==Automated Security Scanners==&lt;br /&gt;
http://brakemanscanner.org/docs/introduction/&lt;br /&gt;
&lt;br /&gt;
= Unresolved Issues =&lt;br /&gt;
== Verbose Servers Headers ==&lt;br /&gt;
== Binding to 0.0.0.0 ==&lt;br /&gt;
== Versioned Secret Tokens ==&lt;br /&gt;
== Logging Values in SQL statements ==&lt;br /&gt;
== Offsite Redirects ==&lt;br /&gt;
&lt;br /&gt;
= Reference =&lt;br /&gt;
http://blog.codeclimate.com/blog/2013/03/27/rails-insecure-defaults/&lt;br /&gt;
&lt;br /&gt;
http://guides.rubyonrails.org/security.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Cookie_sniffing.png&amp;diff=86573</id>
		<title>File:Cookie sniffing.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Cookie_sniffing.png&amp;diff=86573"/>
		<updated>2014-09-18T16:19:07Z</updated>

		<summary type="html">&lt;p&gt;Spsingh2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Spsingh2</name></author>
	</entry>
</feed>