Skip to content

Commit

Permalink
cache allowlist permitted? (#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom authored Oct 12, 2023
1 parent 7dda8ea commit 5d49948
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/dashboard/app/models/allowlist_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def initialize(allowlist)
# @raises ArgumentError if any allowlist path or permitted? argument
# has the form ~user/some/path where user doesn't exist
def permitted?(path)
allowlist.blank? || allowlist.any? { |parent| child?(Pathname.new(parent), real_expanded_path(path.to_s)) }
key = path_to_key(path)
Rails.cache.fetch(key) do
allowlist.blank? || allowlist.any? { |parent| child?(Pathname.new(parent), real_expanded_path(path.to_s)) }
end
end

# @raises AllowlistPolicy::Forbidden if path is not permitted by allowlist
Expand All @@ -29,6 +32,10 @@ def validate!(path)

protected

def path_to_key(path)
"allowlist_permitted_#{path}"
end

# call realpath to ensure symlinks are handled
def real_expanded_path(path)
# call realpath to ensure symlinks are resolved
Expand Down

0 comments on commit 5d49948

Please sign in to comment.