Skip to content

Commit

Permalink
RUBY-783 close security issue in cookie handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarg committed Mar 15, 2012
1 parent 9692df8 commit d910489
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/new_relic/agent/transaction_info.rb
@@ -1,3 +1,5 @@
require 'erb'

module NewRelic
module Agent
class TransactionInfo
Expand Down Expand Up @@ -48,17 +50,22 @@ def self.clear
def self.reset(request=nil)
clear
instance = get
instance.token = get_token(request)
end

if request
agent_flag = request.cookies['NRAGENT']
if agent_flag
s = agent_flag.split("=")
if s.length == 2
if s[0] == "tk" && s[1]
instance.token = s[1]
end
def self.get_token(request)
return nil unless request

agent_flag = request.cookies['NRAGENT']
if agent_flag
s = agent_flag.split("=")
if s.length == 2
if s[0] == "tk" && s[1]
ERB::Util.h(s[1])
end
end
else
nil
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/new_relic/agent/transaction_info_test.rb
@@ -0,0 +1,13 @@
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
require 'ostruct'

class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
def setup
@request = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=1234<tag>evil</tag>5678'})
end

def test_get_token_gets_sanitized_token_from_cookie
assert_equal('1234&lt;tag&gt;evil&lt;/tag&gt;5678',
NewRelic::Agent::TransactionInfo.get_token(@request))
end
end

0 comments on commit d910489

Please sign in to comment.