-
Notifications
You must be signed in to change notification settings - Fork 467
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
Fix cache rendering with namespaced resources #874
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,26 +154,12 @@ def get_format | |
|
||
def render_from_cache | ||
path = Apipie.configuration.doc_base_url.dup | ||
# some params can contain dot, but only one in row | ||
if [:resource, :method, :format, :version].any? { |p| params[p].to_s.gsub(".", "") =~ /\W/ || params[p].to_s.include?('..') } | ||
head :bad_request and return | ||
end | ||
|
||
path << "/" << params[:version] if params[:version].present? | ||
path << "/" << params[:resource] if params[:resource].present? | ||
path << "/" << params[:method] if params[:method].present? | ||
if params[:format].present? | ||
path << ".#{params[:format]}" | ||
else | ||
path << ".html" | ||
end | ||
|
||
# we sanitize the params before so in ideal case, this condition | ||
# will be never satisfied. It's here for cases somebody adds new | ||
# param into the path later and forgets about sanitation. | ||
if path.include?('..') | ||
head :bad_request and return | ||
end | ||
# Sanitize path against directory traversal attacks (e.g. ../../foo) | ||
# by turning path into an absolute path before appending it to the cache dir | ||
path = File.expand_path("#{path}.#{request.format.symbol}", '/') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you are taking the format from the request, but can it be different? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi! Sorry I didn't respond earlier - yesterday was really busy. Since Rails/Rack assemble the request format for us, I figured it was safest to use If we had a large variety request formats it might be possible for I'm more than willing to change this in a new PR if you think we should. Thank you for merging it! (And all my other recent PRs - you are super responsive which is not often found 🎉 ) |
||
|
||
cache_file = File.join(Apipie.configuration.cache_dir, path) | ||
if File.exist?(cache_file) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we are not adding this anymore?