Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit dd45fd8db6f3a15b18714096ebbddaac6b8191ab @Bonias Bonias committed Oct 27, 2010
Showing with 78 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +17 −0 README
  3. +23 −0 Rakefile
  4. +2 −0 init.rb
  5. +1 −0 install.rb
  6. +3 −0 lib/session_protector.rb
  7. +11 −0 lib/warden/callback.rb
  8. +1 −0 uninstall.rb
@@ -0,0 +1,20 @@
+Copyright (c) 2010 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 README
@@ -0,0 +1,17 @@
+= session_protector
+
+* http://github.com/groovyruby/session_protector
+
+== DESCRIPTION:
+
+Logout user if HTTP_USER_AGENT and IP differ from ones saved in session. This make harder to successfull use session hijacking tools like firesheep(http://codebutler.com/firesheep).
+
+== REQUIREMENTS:
+
+Devise or other authentication system based on Warden
+
+== INSTALL:
+
+rails plugin install http://github.com/groovyruby/session_protector.git
+
+Copyright (c) 2010 [name of plugin creator], released under the MIT license
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the session_protector plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the session_protector plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'SessionProtector'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,2 @@
+require 'session_protector'
+require 'warden/callback'
@@ -0,0 +1 @@
+# Install hook code here
@@ -0,0 +1,3 @@
+module SessionProtector
+ VERSION = '0.0.1'
+end
@@ -0,0 +1,11 @@
+Warden::Manager.after_set_user do |record, warden, options|
+ scope = options[:scope]
+ if !warden.env['HTTP_USER_AGENT'].nil?
+ required_string = "#{warden.env['HTTP_USER_AGENT']}-#{warden.request.remote_ip}"
+ if warden.session(scope)['user_agent_with_ip'].blank?
+ warden.session(scope)['user_agent_with_ip'] = required_string
+ elsif required_string != warden.session(scope)['user_agent_with_ip']
+ warden.logout(scope)
+ end
+ end
+end
@@ -0,0 +1 @@
+# Uninstall hook code here

0 comments on commit dd45fd8

Please sign in to comment.