Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to change TTL on AccessVerifier #1941

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/models/users/access_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

module Users
module AccessVerifier
TTL_MINUTES = 5

class InvalidVerifier < RuntimeError
end

Expand All @@ -40,7 +38,7 @@ def self.generate(claims)
jwt_claims[:root_account_id] = root_account.global_id.to_s if root_account
jwt_claims.merge!(claims.slice(:oauth_host, :return_url, :fallback_url))

expires = TTL_MINUTES.minutes.from_now
expires = Setting.get("access_verifier.ttl_minutes", "5").to_i.minutes.from_now
key = nil # use default key
{ sf_verifier: Canvas::Security.create_jwt(jwt_claims, expires, key, :HS512) }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/files_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def file_with_path(path)

# second use after verifier expiration but before session expiration.
# expired verifier should be ignored but session should still be extended
Timecop.freeze((Users::AccessVerifier::TTL_MINUTES + 1).minutes.from_now) do
Timecop.freeze((Setting.get("access_verifier.ttl_minutes", "5").to_i + 1).minutes.from_now) do
get "show", params: verifier.merge(id: file.id)
end
expect(response).to be_successful
Expand Down
2 changes: 1 addition & 1 deletion spec/models/users/access_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Users

it "raises InvalidVerifier if too old" do
verifier = Users::AccessVerifier.generate(user: user)
Timecop.freeze(10.minutes.from_now) do
Timecop.freeze((Setting.get("access_verifier.ttl_minutes", "5").to_i + 1).minutes.from_now) do
expect { Users::AccessVerifier.validate(verifier) }.to raise_exception(Canvas::Security::TokenExpired)
end
end
Expand Down