Merge branch 'master' into cd-v3-parity
This commit is contained in:
commit
77aabcb78f
|
@ -78,6 +78,7 @@ class Travis::Api::App
|
||||||
#
|
#
|
||||||
# * **github_token**: GitHub token for checking authorization (required)
|
# * **github_token**: GitHub token for checking authorization (required)
|
||||||
post '/github' do
|
post '/github' do
|
||||||
|
check_agent
|
||||||
unless params[:github_token]
|
unless params[:github_token]
|
||||||
halt 422, { "error" => "Must pass 'github_token' parameter" }
|
halt 422, { "error" => "Must pass 'github_token' parameter" }
|
||||||
end
|
end
|
||||||
|
@ -145,6 +146,16 @@ class Travis::Api::App
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def allowed_agents
|
||||||
|
@allowed_agents ||= redis.smembers('auth_agents')
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_agent
|
||||||
|
return if settings.test? or allowed_agents.empty?
|
||||||
|
return if allowed_agents.any? { |a| request.user_agent.to_s.start_with? a }
|
||||||
|
halt 403, "you are currently not allowed to perform this request. please contact support@travis-ci.com."
|
||||||
|
end
|
||||||
|
|
||||||
def serialize_user(user)
|
def serialize_user(user)
|
||||||
rendered = Travis::Api.data(user, version: :v2)
|
rendered = Travis::Api.data(user, version: :v2)
|
||||||
rendered['user'].merge('token' => user.tokens.first.try(:token).to_s)
|
rendered['user'].merge('token' => user.tokens.first.try(:token).to_s)
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Travis::Api::App
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_travis(agent)
|
def mark_travis(agent)
|
||||||
command = agent.application.comment.detect { |c| c.start_with? "command " }
|
command = agent.application.comment.detect { |c| c.start_with? "command " } if agent.application.comment
|
||||||
|
|
||||||
if command
|
if command
|
||||||
mark(:cli, :version, agent.version)
|
mark(:cli, :version, agent.version)
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Rack::Attack
|
||||||
# Ban time: 5 hours
|
# Ban time: 5 hours
|
||||||
# Ban after: 10 POST requests within five minutes to /auth/github
|
# Ban after: 10 POST requests within five minutes to /auth/github
|
||||||
blacklist('hammering /auth/github') do |request|
|
blacklist('hammering /auth/github') do |request|
|
||||||
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 10, findtime: 5.minutes, bantime: bantime(5.hours)) do
|
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 2, findtime: 5.minutes, bantime: bantime(5.hours)) do
|
||||||
request.post? and request.path == '/auth/github'
|
request.post? and request.path == '/auth/github'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,6 +59,14 @@ class Rack::Attack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Throttle: unauthenticated requests to /auth/github - 1 per minute
|
||||||
|
# Scoped by: IP address
|
||||||
|
throttle('req/ip/1min', limit: 1, period: 1.minute) do |request|
|
||||||
|
request.ip unless request.authenticated? and request.path == '/auth/github'
|
||||||
|
end
|
||||||
|
|
||||||
###
|
###
|
||||||
# Throttle: unauthenticated requests - 500 per minute
|
# Throttle: unauthenticated requests - 500 per minute
|
||||||
# Scoped by: IP address
|
# Scoped by: IP address
|
||||||
|
|
|
@ -8,6 +8,7 @@ module Travis::API::V3
|
||||||
user = Models::User.find(user.id) if user.is_a? ::User
|
user = Models::User.find(user.id) if user.is_a? ::User
|
||||||
@user = user
|
@user = user
|
||||||
@access_permissions = user.permissions.where(user_id: user.id)
|
@access_permissions = user.permissions.where(user_id: user.id)
|
||||||
|
@got_request = false
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ module Travis::API::V3
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible_repositories(list)
|
def visible_repositories(list)
|
||||||
|
load_permissions
|
||||||
list.where('repositories.private = false OR repositories.id IN (?)'.freeze, access_permissions.map(&:repository_id))
|
list.where('repositories.private = false OR repositories.id IN (?)'.freeze, access_permissions.map(&:repository_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,7 +49,19 @@ module Travis::API::V3
|
||||||
|
|
||||||
def permission?(type, id)
|
def permission?(type, id)
|
||||||
id = id.id if id.is_a? ::Repository
|
id = id.id if id.is_a? ::Repository
|
||||||
access_permissions.where(type => true, :repository_id => id).any?
|
|
||||||
|
load_permissions if @got_request
|
||||||
|
@got_request = true
|
||||||
|
|
||||||
|
if access_permissions.respond_to? :where
|
||||||
|
access_permissions.where(type => true, :repository_id => id).any?
|
||||||
|
else
|
||||||
|
access_permissions.any? { |p| p[type] == true and p.repository_id == id }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_permissions
|
||||||
|
@access_permissions = @access_permissions.to_a
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user