Security guidelines for Expertiza: Difference between revisions
No edit summary |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
Each of the security upgrades covered in this section contribute to the end goal of a more secure Expertiza. | Each of the security upgrades covered in this section contribute to the end goal of a more secure Expertiza. | ||
===Encryption== | ===Encryption=== | ||
A lot of information stored in the Expertiza database is personally identifiable. Expertiza now implements transparent encryption of the data at rest to ensure that a comprise of the actual | A lot of information stored in the Expertiza database is personally identifiable. Expertiza now implements transparent encryption of the data at rest to ensure that a comprise of the actual | ||
database or data leak does not yield any useful information to the adversary. This satisfies Expertiza's security goal of ensuring confidentiality. | database or data leak does not yield any useful information to the adversary. This satisfies Expertiza's security goal of ensuring confidentiality. | ||
Encryption can simply be added to any model by calling a new method provided by Expertiza's security module. Before implementing encryption, a few considerations will have to be made. The attributes that have to be encrypted have to be a string to text type, since the output of any encryption method is an encrypted text block. To encrypted numerical, time or other attributes, the attributes must be converted to string before being stored in the database and converted to the appropriate type in Rails. | |||
====Adding encryption to an Expertiza model==== | |||
Encryption in Expertiza uses the security module of Expertiza, so you must require the security module before you can add encryption to a model and then include the ExpertizaSecurity class that handles all the encryption and decryption in the background. The pass the name of the encrypted attribute to the attr_encrypted method. | |||
# /app/models/team.rb | |||
class Team < ActiveRecord::Base | |||
require 'expertiza_security' | |||
include ExpertizaSecurity | |||
attr_encrypted :grade_for_submission | |||
end | |||
====Encrypting existing data==== | |||
Since encryption in Expertiza relies on callbacks after initialize and before save to perform encryption, existing data will not be encrypted immediately encryption has been added. The data will only be encrypted if it changes. If the entire model needs to be encrypted, it is possible to call the save method on the model to save and encrypt the data. | |||
It possible to achieve this by defining a method in the model class. | |||
# /app/models/team.rb | |||
class Team < ActiveRecord::Base | |||
def self.save_all | |||
Team.all.each { |team| save.save! } | |||
end | |||
end | |||
Then you can just call the save_all method on the model call. | |||
Team.save_all | |||
This will call the save! method on call instances of the class, and the data will be encrypted before save. | |||
However, this may not always be practical or desirable. After all, adding encryption is usually a one time even. In these cases, it is usually more practical to using the rails console and call the save method on model class. | |||
Team.find_each(&:save) | |||
When dealing with large database, there is usually a lot of records and this can take a lot of time to encrypt. You can define a method on find the records in batches and call the save method on themm | |||
Team.find_each(:batch_size => 1000) do |team| | |||
team.save! | |||
end |
Latest revision as of 15:52, 2 May 2018
Security Guidelines
Web applications such as Expertiza present a complex set of security issues for users, designers, and developers. The most secure and hack-resilient Web applications are those that have been built from the ground up with security in mind.
In addition to applying sound architectural and design practices, incorporate deployment considerations and corporate security policies during the early design phases. Failure to do so can result in applications that cannot be deployed on an existing infrastructure without compromising security.
This guideline presents a set of secure architecture and design guidelines we have followed to ensure that Expertiza is designed with security at it's core.
Security Upgrades
Each of the security upgrades covered in this section contribute to the end goal of a more secure Expertiza.
Encryption
A lot of information stored in the Expertiza database is personally identifiable. Expertiza now implements transparent encryption of the data at rest to ensure that a comprise of the actual database or data leak does not yield any useful information to the adversary. This satisfies Expertiza's security goal of ensuring confidentiality.
Encryption can simply be added to any model by calling a new method provided by Expertiza's security module. Before implementing encryption, a few considerations will have to be made. The attributes that have to be encrypted have to be a string to text type, since the output of any encryption method is an encrypted text block. To encrypted numerical, time or other attributes, the attributes must be converted to string before being stored in the database and converted to the appropriate type in Rails.
Adding encryption to an Expertiza model
Encryption in Expertiza uses the security module of Expertiza, so you must require the security module before you can add encryption to a model and then include the ExpertizaSecurity class that handles all the encryption and decryption in the background. The pass the name of the encrypted attribute to the attr_encrypted method.
# /app/models/team.rb class Team < ActiveRecord::Base require 'expertiza_security' include ExpertizaSecurity attr_encrypted :grade_for_submission end
Encrypting existing data
Since encryption in Expertiza relies on callbacks after initialize and before save to perform encryption, existing data will not be encrypted immediately encryption has been added. The data will only be encrypted if it changes. If the entire model needs to be encrypted, it is possible to call the save method on the model to save and encrypt the data.
It possible to achieve this by defining a method in the model class.
# /app/models/team.rb class Team < ActiveRecord::Base def self.save_all Team.all.each { |team| save.save! } end end
Then you can just call the save_all method on the model call.
Team.save_all
This will call the save! method on call instances of the class, and the data will be encrypted before save.
However, this may not always be practical or desirable. After all, adding encryption is usually a one time even. In these cases, it is usually more practical to using the rails console and call the save method on model class.
Team.find_each(&:save)
When dealing with large database, there is usually a lot of records and this can take a lot of time to encrypt. You can define a method on find the records in batches and call the save method on themm
Team.find_each(:batch_size => 1000) do |team| team.save! end