Skip to content

Support current in URL #1417

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Support current in URL #1417

wants to merge 2 commits into from

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Feb 22, 2023

Closes #1215

@@ -5,6 +5,11 @@
after_action :set_feature_headers

def set_ruby_version
if params[:version] == "current"
redirect_to request.path.sub(%r{^/current}, "/#{RubyConfig.default_ruby_version.version}")

Check warning

Code scanning / CodeQL

URL redirection from remote source

Untrusted URL redirection depends on a [user-provided value](1).
Copy link
Contributor

@natematykiewicz natematykiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really like to address the CodeQL security warning here.

What if you do something more like this?

redirect_to params.merge(version: RubyConfig.default_ruby_version.version)

@@ -5,6 +5,12 @@
after_action :set_feature_headers

def set_ruby_version
if params[:version] == "current"
permitted_params = params.permit(:object, :engine, :q, :page, :theme)
redirect_to permitted_params.merge(version: RubyConfig.default_ruby_version.version)

Check warning

Code scanning / CodeQL

URL redirection from remote source

Untrusted URL redirection depends on a [user-provided value](1).
@andyw8
Copy link
Contributor Author

andyw8 commented Feb 26, 2023

@natematykiewicz thanks for the suggestion, I've pushed an update.

It's a little awkward since it needs to be aware of all the potential params which could be passed.

Also, CodeQL still complains 😭

@colby-swandale
Copy link
Member

I wonder if the user experience could improved by having latest act as a transparent alias of the latest version to save on needing to redirect?

@natematykiewicz
Copy link
Contributor

natematykiewicz commented Mar 2, 2023

Alternatively, I wonder if a redirect can be added directly in the router.

Would that help anything? I know there's route constraint classes you can make.

Or maybe a middleware?

I just don't love having to list out all of the possible params. Seems really prone to failure as we add more pages in the future. I understand why you needed to do it (because only permitted params will get returned). That's why I wonder if bringing the controller into this is too far down the line.

@andyw8
Copy link
Contributor Author

andyw8 commented Mar 3, 2023

Alternatively, I wonder if a redirect can be added directly in the router.
Would that help anything? I know there's route constraint classes you can make.

It's possible, but I expect that would still have the same issues with untrusted URL redirection.

@andyw8 andyw8 mentioned this pull request Mar 4, 2023
@andyw8
Copy link
Contributor Author

andyw8 commented Mar 4, 2023

I wonder if the user experience could improved by having latest act as a transparent alias of the latest version to save on needing to redirect?

#1426

@natematykiewicz
Copy link
Contributor

natematykiewicz commented Mar 4, 2023

I really like the simplicity of #1426, and the lack of a redirect does seem nice.

I'm a bigger fan of current than latest though. Maybe that's because the Postgres docs say "current". I do notice that the Postgres docs don't redirect, which is nice because then all of the links everywhere say "current" instead of "15".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce current in url
3 participants