SafeParamsHelper::safe_params is not so safe
The safe_params helper only filtered host, port and protocol, leaving other reserved Rails URL options such as domain and script_name controllable. An attacker could craft links that cause open redirects or, in some views, reflected cross-site scripting.
- Triaged in 2 hours
- Fixed in 2 months
- Paid in 2 hours
- Disclosed after 3 months
Summary
GitLab uses SafeParamsHelper to filter out some keys before passing them to url_for:
def safe_params
if params.respond_to?(:permit!)
params.except(:host, :port, :protocol).permit!
else
params
end
end
The issue is that there are a lot more dangerous keys:
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
:trailing_slash, :anchor, :params, :only_path, :script_name,
:original_script_name, :relative_url_root]
This means that anywhere safe_params is used, the domain could be changed using the domain query. Most of the build_canonical_path methods call url_for(safe_params) which then gets used by RoutableActions:
def ensure_canonical_path(routable, requested_full_path)
return unless request.get?
canonical_path = routable.full_path
if canonical_path != requested_full_path
if !request.xhr? && request.format.html? && canonical_path.casecmp(requested_full_path) != 0
flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path."
end
redirect_to build_canonical_path(routable)
end
end
This creates an open redirect in all of the RoutableActions routes by making canonical_path != requested_full_path (eg using a capital letter) and adding the domain param:
- Visit https://gitlab.com/vakzz-h1/Redirect1?domain=aw.rs
- You will be redirected to https://aw.rs/
The other key that can be abused is script_name, as this is appended to the start of the url and can be used to fake a protocol such as javascript:
-
Visit https://gitlab.com/vakzz-h1/redirect1/-/issues?script_name=javascript:alert(1)//
-
Look at the RSS Feed link
HTML
1. On gitlab.com this is blocked by the CSP
There are a bunch of other places that use `safe_params` that could be exploited such as the [_viewer.html.haml](https://gitlab.com/gitlab-org/gitlab/-/blob/682a3c0134f2cfec9e5743aa97fbaf2a7d89e65fapp/views/projects/blob/_viewer.html.haml#L7)
```haml
- viewer_url = local_assigns.fetch(:viewer_url) { url_for(safe_params.merge(viewer: viewer.type, format: :json)) } if load_async
.blob-viewer{ data: { type: viewer.type, rich_type: rich_type, url: viewer_url, path: viewer.blob.path }, class: ('hidden' if hidden) }
This allows an attacker to specify the viewer_url for the blob url. Since the json returned by the url has an html attributes it allows arbitrary html to be inserted. The below uses https://gitlab.com/-/snippets/1999965 as the viewer url and 1 click csp bypass (same as https://hackerone.com/reports/662287#activity-6026826) with https://gitlab.com/-/snippets/1999974/raw for the js payload:
-
Visit https://gitlab.com/vakzz-h1/redirect1/-/blob/master/test.txt?script_name=/-/snippets/1999965/raw%23
-
See the injected HTML:
HTML
I've only skimmed the other locations that use safe_params but it looks like there are a few more that load data via javascript or could be turned into open redirects. I also haven't looked into the impact of the open redirects to see if they could be escalated to leak sensitive information, I'll update the report if I find anything else.
I've put all of these in a single report as the mitigation is the same for all of them, but if you would like me to split them into separate reports I can do that as well. I've also set the severity to high due to the number of places that this is used and relative ease of trigger it, but the individual issues are probably less so might need to be adjusted.
What is the current bug behavior?
SafeParamsHelper.safe_params only filters out the keys :host, :port, :protocol but there are other dangerous ones
What is the expected correct behavior?
SafeParamsHelper.safe_params should filter out all of the reserved options:
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
:trailing_slash, :anchor, :params, :only_path, :script_name,
:original_script_name, :relative_url_root]
Output of checks
This bug happens on GitLab.com
Impact
- open redirect on quire a few routes
- reflected xss using the
javascriptprotocol - reflected xss with csp bypass using the blob viewer
Context
GitLab is a web based Git repository and DevOps platform. The report concerns a helper used throughout the Rails application, SafeParamsHelper, and specifically its safe_params method. The helper exists to take the current request's parameters and strip out keys that would be dangerous if they were passed through to Rails' url_for, so that generated URLs stay on the intended host and path.
The method as it stood is shown in the report:
def safe_params
if params.respond_to?(:permit!)
params.except(:host, :port, :protocol).permit!
else
params
end
end
In other words, it removes :host, :port and :protocol and permits everything else. The filtered parameters are then handed to url_for in a number of places, most notably the build_canonical_path methods used by the RoutableActions concern, and the blob viewer template.
Setup
The report does not describe any special setup: no accounts, roles, tools or versions are listed. The researcher used their own namespace on gitlab.com (vakzz-h1) with a project (redirect1) and a file (test.txt) to demonstrate the issues, and states that the bug happens on GitLab.com. The snippets referenced in the XSS section are hosted on gitlab.com itself.
Finding it
The researcher compared the list of keys that safe_params removes with the list of reserved options that Rails' routing layer treats specially. Rails defines a much larger set:
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
:trailing_slash, :anchor, :params, :only_path, :script_name,
:original_script_name, :relative_url_root]
Only three of these (:host, :port, :protocol) were being stripped. That means that anywhere safe_params is used, an attacker can still supply keys such as domain or script_name and have Rails interpret them as routing options rather than as ordinary query parameters. The researcher notes that this means the domain could be changed using the domain query parameter.
Exploitation
Open redirect via domain
Most of the build_canonical_path methods call url_for(safe_params), and the result is used by RoutableActions:
def ensure_canonical_path(routable, requested_full_path)
return unless request.get?
canonical_path = routable.full_path
if canonical_path != requested_full_path
if !request.xhr? && request.format.html? && canonical_path.casecmp(requested_full_path) != 0
flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path."
end
redirect_to build_canonical_path(routable)
end
end
The condition for the redirect is that canonical_path != requested_full_path. Because the comparison is case sensitive, requesting a path with a capital letter is enough to make the two differ, which triggers redirect_to build_canonical_path(routable). Since build_canonical_path builds its URL from safe_params, and domain survives the filter, the redirect target's domain can be controlled.
- Visit:
https://gitlab.com/vakzz-h1/Redirect1?domain=aw.rs
- The response redirects to:
https://aw.rs/
The capital R in Redirect1 makes the requested path differ from the canonical path, and the domain parameter is not filtered out. The report states that this creates an open redirect in all of the RoutableActions routes.
Reflected XSS via script_name
The second abusable key is script_name. Rails prepends it to the start of the generated URL, which lets an attacker place an arbitrary scheme at the front, such as javascript:.
- Visit:
https://gitlab.com/vakzz-h1/redirect1/-/issues?script_name=javascript:alert(1)//
- Inspect the RSS feed link on the page:
<a class="btn btn-svg has-tooltip" data-container="body" title="" href="javascript:alert(1)//vakzz-h1/redirect1/-/issues.atom?feed_token=XXXX&state=opened" data-original-title="Subscribe to RSS feed">
<svg class="s16 qa-rss-icon" data-testid="rss-icon">
<use xlink:href="https://gitlab.com/assets/icons-[redacted].svg#rss"></use>
</svg>
</a>
The href now begins with javascript:alert(1)//, with the rest of the legitimate path following after the // so that it is treated as part of the script URL. The report notes that on gitlab.com this particular payload is blocked by the Content Security Policy.
Reflected XSS with CSP bypass via the blob viewer
The researcher points to other places that use safe_params, including _viewer.html.haml:
- viewer_url = local_assigns.fetch(:viewer_url) { url_for(safe_params.merge(viewer: viewer.type, format: :json)) } if load_async
.blob-viewer{ data: { type: viewer.type, rich_type: rich_type, url: viewer_url, path: viewer.blob.path }, class: ('hidden' if hidden) }
Here safe_params is merged with the viewer type and JSON format and passed to url_for to produce the URL the blob viewer fetches asynchronously. Because script_name is not filtered, an attacker can control the viewer_url for the blob. The JSON returned by that URL contains an html attribute, so if the attacker points the viewer at a URL they control that returns such JSON, arbitrary HTML is inserted into the page.
The researcher used https://gitlab.com/-/snippets/1999965 as the viewer URL, and https://gitlab.com/-/snippets/1999974/raw as the JavaScript payload, describing this as a one click CSP bypass (the same technique as referenced in an earlier report).
- Visit:
https://gitlab.com/vakzz-h1/redirect1/-/blob/master/test.txt?script_name=/-/snippets/1999965/raw%23
- The injected HTML appears in the page:
<form>any <b>html</b> can go <button>here<a data-remote="true" data-method="get" data-type="script" href="https://gitlab.com/-/snippets/1999974/raw" class="atwho-view select2-drop-mask pika-select">
<img width="10000" height="10000">
</a></button></form>
- Clicking anywhere triggers an alert.
The script_name value /-/snippets/1999965/raw%23 is prepended to the generated viewer URL, so the viewer fetches the attacker's snippet. The snippet returns JSON with an html attribute containing the markup above, which the viewer inserts into the DOM. The injected anchor points at the raw snippet at https://gitlab.com/-/snippets/1999974/raw, and clicking anywhere triggers an alert.
The researcher notes having only skimmed the other locations that use safe_params, and that a few more appear to load data via JavaScript or could be turned into open redirects. They also state that they had not looked into whether the open redirects could be escalated to leak sensitive information, and would update the report if they found anything else. All of the issues were put in a single report because the mitigation is the same for all of them, with an offer to split them if desired. The severity was set to high because of the number of places the helper is used and the relative ease of triggering it, while acknowledging that the individual issues are probably less severe and might need adjusting.
Root cause
The mistake is an incomplete deny list. safe_params removes only :host, :port and :protocol, but Rails' routing layer recognises a much larger set of reserved options. Any of the remaining keys that reach url_for are interpreted as routing options rather than as ordinary parameters, so user input can influence the generated URL's scheme, host or path prefix. The existing filter therefore gives a false sense of safety: the method is named as though it sanitises parameters, but it only covers three of the reserved keys.
Impact
The report lists three impacts:
- open redirect on quite a few routes;
- reflected XSS using the
javascriptprotocol; - reflected XSS with a CSP bypass using the blob viewer.
The open redirect works on the RoutableActions routes whenever the requested path differs from the canonical path (for example through a capital letter) and a domain parameter is supplied. The script_name based XSS is reflected through generated links such as the RSS feed link, though on gitlab.com that variant is blocked by the CSP. The blob viewer variant achieves script execution despite the CSP by loading an attacker controlled snippet as a script after a click. The researcher did not investigate whether the open redirects could be escalated to leak sensitive information.
Fix
The report states that SafeParamsHelper.safe_params should filter out all of the reserved options:
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
:trailing_slash, :anchor, :params, :only_path, :script_name,
:original_script_name, :relative_url_root]
The report proposes filtering out all of the reserved options, since the same helper underlies every variant.
Variants to test
- Supply
domainon any route that goes throughRoutableActionsand make the requested path differ from the canonical path (for example with a capital letter). A positive result is a redirect whose host is the supplied domain. - Supply
script_namewith ajavascript:scheme followed by//on pages that render links built fromsafe_params. A positive result is a generatedhrefbeginning withjavascript:. - Supply
script_namepointing at a URL you control that returns JSON with anhtmlattribute on the blob viewer. A positive result is your markup appearing in the page. - Try the other reserved options that the helper does not strip, such as
subdomain,only_path,anchorandparams, whereversafe_paramsfeedsurl_for, and observe whether the generated URL changes in a way you control.
Hunting notes
This kind of bug hides in helpers that try to sanitise parameters before passing them to framework URL builders. The signal is a deny list that names only a few keys while the framework documents a larger set of reserved options; comparing the two lists is usually enough to spot the gap. Once a helper like this is found, grep for its call sites: redirect builders, canonical path logic and templates that embed a URL in a data attribute are the most promising. The researcher demonstrated impact by chaining the parameter into a redirect, into a generated link, and finally into an asynchronous viewer that inserts server returned HTML, using a same origin snippet to satisfy the CSP. Grouping the findings under one report made sense because a single fix covers them all.
What happened, in plain words
GitLab is a website where teams store and share code, track issues and run their software projects. Like most large websites, it is built from many small reusable pieces of code. One of those pieces is called SafeParamsHelper, and it exists to make web addresses (URLs) that GitLab generates safe to use.
A URL is the address you type into your browser, such as https://gitlab.com/some-project. When GitLab builds a URL, it takes the pieces of the current request and glues them together. Some of those pieces come from the visitor, and a visitor can put anything they like into them. If GitLab blindly copies visitor-supplied pieces into a URL, the visitor can change where that URL points.
The helper was supposed to prevent exactly that. It removed three dangerous pieces before building the URL. The problem, as the researcher found, is that the underlying web framework (Ruby on Rails) treats many more pieces as special. The helper only removed three of them, so a visitor could still slip in the others and bend the generated URL to their will. That let the researcher redirect people to another website, and in some places run their own JavaScript code inside GitLab's pages.
The context: what the helper does and why it matters
GitLab runs on a framework called Ruby on Rails. Rails has a built-in tool called url_for whose job is to assemble a URL out of a set of named pieces. You give it things like a host, a path and some parameters, and it returns a finished address.
Some of those named pieces are special. If you pass host, Rails uses it as the domain name of the resulting URL. If you pass script_name, Rails sticks it at the front of the path. These are called reserved options: names that Rails interprets as instructions about how to build the URL, rather than as ordinary data to be carried along in the query string.
The query string is the part of a URL after the ?, made of key=value pairs. For example, in https://example.com/page?colour=blue, colour is a parameter with the value blue. Normally a parameter is just data. But if its name happens to be one of Rails' reserved options, Rails treats it as an instruction instead.
That is the danger. If a visitor can add ?domain=evil.example to a GitLab URL, and GitLab passes that parameter straight into url_for, Rails may build a URL pointing at evil.example instead of gitlab.com.
To stop this, GitLab wrote a helper called SafeParamsHelper. Its safe_params method takes the current request's parameters and removes the dangerous ones before they reach url_for. The version in the report looked like this:
def safe_params
if params.respond_to?(:permit!)
params.except(:host, :port, :protocol).permit!
else
params
end
end
Line by line:
def safe_paramsstarts the definition of a method namedsafe_params.if params.respond_to?(:permit!)checks whether the parameters object supports a method calledpermit!. This is a Rails feature that marks parameters as allowed to be used. The check exists because the object might not always be that kind of object.params.except(:host, :port, :protocol).permit!is the core.paramsholds everything the visitor sent..except(:host, :port, :protocol)makes a copy with those three names removed..permit!then marks everything that remains as allowed.elseandparamsmean: if the object does not supportpermit!, just return the parameters unchanged.endcloses the method.
In plain words: the helper deletes host, port and protocol, and lets everything else through. host is the domain name, port is the numbered channel a server listens on, and protocol is the scheme such as https. Removing those three sounds sensible, and it is, but only if those three are the only dangerous names. They are not.
Finding the gap
The researcher did something simple and effective: they compared the list of names the helper removed with the list of names Rails itself treats as reserved. Rails publishes that list in its own source code:
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
:trailing_slash, :anchor, :params, :only_path, :script_name,
:original_script_name, :relative_url_root]
This is a list of names Rails will interpret as routing instructions. Reading it:
:host,:protocoland:portare the three the helper already removed.:subdomainand:domainlet you influence which part of the domain name is used.:tld_lengthtells Rails how many dot-separated parts at the end of a domain form the top-level domain, such as.com.:trailing_slashcontrols whether the URL ends with a/.:anchoris the#fragmentpart at the end of a URL.:paramslets you inject extra query parameters.:only_pathdecides whether the result is a full URL or just a path.:script_nameis a prefix added to the start of the path.:original_script_nameand:relative_url_rootare related prefix options.
Only three of these were being stripped. The other ten could still arrive from the visitor and be treated as instructions by Rails. The researcher singled out two as the most useful: domain and script_name.
This kind of mistake has a name: an incomplete deny list. A deny list is a list of things you forbid. It only works if it is complete. A useful everyday comparison: telling a child "you may not eat the biscuits or the cake" while the chocolate is still in the cupboard. The rule sounds like a rule, but it leaves a gap. The method was called safe_params, which gave a false sense of safety, because it only covered a fraction of the reserved names.
Exploitation 1: an open redirect using domain
An open redirect is a flaw where a website can be made to send a visitor to an address chosen by someone else. It is dangerous because the link starts on the trusted site. A victim sees gitlab.com at the beginning and clicks, then lands on an attacker's page that may look like a login screen.
GitLab has a mechanism for keeping URLs tidy. If you request a page using a slightly different spelling of its address, GitLab redirects you to the official spelling. This is called the canonical path: the one true address of a page. The code that does this is in a shared piece called RoutableActions:
def ensure_canonical_path(routable, requested_full_path)
return unless request.get?
canonical_path = routable.full_path
if canonical_path != requested_full_path
if !request.xhr? && request.format.html? && canonical_path.casecmp(requested_full_path) != 0
flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_full_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path."
end
redirect_to build_canonical_path(routable)
end
end
Line by line:
def ensure_canonical_path(routable, requested_full_path)defines a method that receives the page object and the path the visitor actually asked for.return unless request.get?means: only continue if this was a normal page request (a GET), not a form submission or something else.canonical_path = routable.full_pathfetches the official address of the page.if canonical_path != requested_full_pathchecks whether the official address differs from what was requested. If they are identical, nothing happens.- The inner
ifchecks three more things: the request is not an AJAX request (!request.xhr?), the visitor wants an HTML page (request.format.html?), and the two paths differ even when letter case is ignored (canonical_path.casecmp(requested_full_path) != 0). If all three hold, it sets a friendly notice telling the user the page moved. redirect_to build_canonical_path(routable)sends the browser to the official address. This is the line that matters.- The closing
ends finish the blocks.
The key detail is the comparison canonical_path != requested_full_path. It is case sensitive. So if you request a page with a capital letter somewhere, the two strings differ, and the redirect fires. The redirect target is produced by build_canonical_path, which builds its URL from safe_params. Since domain survives the filter, the visitor controls the domain of the redirect target.
The researcher demonstrated it like this:
- Visit:
https://gitlab.com/vakzz-h1/Redirect1?domain=aw.rs
- The response redirects to:
https://aw.rs/
Why this works: the capital R in Redirect1 makes the requested path differ from the official lowercase path, so the redirect logic runs. The domain=aw.rs parameter is not removed by safe_params, so Rails reads it as an instruction to use aw.rs as the domain. The browser is sent to https://aw.rs/. The report states this creates an open redirect on all of the routes that use RoutableActions.
Exploitation 2: reflected XSS using script_name
XSS stands for cross-site scripting. It means getting your own JavaScript code to run inside someone else's website, in the context of that site. JavaScript is the programming language browsers run to make pages interactive. If an attacker's JavaScript runs on gitlab.com, it can act with the visitor's permissions: read what the page shows, click things on their behalf, and so on. Reflected means the malicious input is not stored on the server; it is bounced straight back in the response to whoever sent it.
The second reserved name the researcher abused is script_name. Rails puts script_name at the very front of the generated URL. If you set it to something beginning with javascript:, the finished URL starts with javascript: instead of https:. A browser treats a javascript: URL as code to run when the link is clicked.
- Visit:
https://gitlab.com/vakzz-h1/redirect1/-/issues?script_name=javascript:alert(1)//
- Look at the RSS feed link on the page:
<a class="btn btn-svg has-tooltip" data-container="body" title="" href="javascript:alert(1)//vakzz-h1/redirect1/-/issues.atom?feed_token=XXXX&state=opened" data-original-title="Subscribe to RSS feed">
<svg class="s16 qa-rss-icon" data-testid="rss-icon">
<use xlink:href="https://gitlab.com/assets/icons-[redacted].svg#rss"></use>
</svg>
</a>
What this HTML shows:
<a ...>is a link. Itshrefattribute is the address the browser goes to when clicked.- The
hrefnow begins withjavascript:alert(1)//.alert(1)is the simplest possible JavaScript: it pops up a box saying 1. The//separates the injected code from the legitimate path that follows. - The rest of the attributes are styling and tooltip information for the button.
- The
<svg>and<use>elements draw the little RSS icon next to the link.
So the page's own RSS subscribe button now points at attacker-supplied JavaScript. If a visitor clicks it, the code runs. The report notes that on gitlab.com this particular payload is blocked by the Content Security Policy, which is a browser rule that limits which scripts a page may run. That defence stopped this variant, but the researcher found a way around it, described next.
Exploitation 3: XSS with a CSP bypass through the blob viewer
A blob is simply a file stored in a Git repository. GitLab has a file viewer that shows blobs in the browser. To make pages load quickly, the viewer fetches the file's contents in the background using JavaScript, from a URL built by the server. That URL is assembled in a template called _viewer.html.haml:
- viewer_url = local_assigns.fetch(:viewer_url) { url_for(safe_params.merge(viewer: viewer.type, format: :json)) } if load_async
.blob-viewer{ data: { type: viewer.type, rich_type: rich_type, url: viewer_url, path: viewer.blob.path }, class: ('hidden' if hidden) }
Line by line:
- The first line sets a variable
viewer_url.local_assigns.fetch(:viewer_url)means: use a value calledviewer_urlif one was passed in; otherwise, run the block in braces. That block callsurl_forwithsafe_paramsmerged with the viewer type and a request for JSON. JSON is a plain text format for exchanging data between programs. The trailingif load_asyncmeans this only happens when the viewer is set to load asynchronously, that is, in the background. - The second line renders the viewer element. The
data:section attaches extra information to the HTML element asdata-attributes: the viewer type, a rich type, the URL to fetch, and the file path. Theclass: ('hidden' if hidden)adds a CSS class that hides the element when needed.
The important part is that the URL the viewer fetches comes from safe_params. Since script_name is not filtered, an attacker can control that URL. The JSON returned from that URL contains an html attribute, and the viewer inserts whatever is in that attribute into the page. So if the attacker points the viewer at a URL they control that returns JSON with an html field, their HTML ends up in GitLab's page.
The researcher used https://gitlab.com/-/snippets/1999965 as the viewer URL and https://gitlab.com/-/snippets/1999974/raw as the JavaScript payload. A snippet is a small piece of shared code hosted on GitLab. The researcher used a snippet hosted on gitlab.com for the JavaScript payload. The researcher describes this as a one click CSP bypass, the same technique as in an earlier report.
- Visit:
https://gitlab.com/vakzz-h1/redirect1/-/blob/master/test.txt?script_name=/-/snippets/1999965/raw%23
- The injected HTML appears in the page:
<form>any <b>html</b> can go <button>here<a data-remote="true" data-method="get" data-type="script" href="https://gitlab.com/-/snippets/1999974/raw" class="atwho-view select2-drop-mask pika-select">
<img width="10000" height="10000">
</a></button></form>
- Clicking anywhere triggers an alert.
What is happening:
- The
script_namevalue/-/snippets/1999965/raw%23is placed at the front of the viewer URL. - The viewer therefore fetches the attacker's snippet, which returns JSON containing an
htmlattribute with the markup shown above. - That markup is inserted into the page. It is a form containing bold text, a button and a link. The link carries
data-remote,data-methodanddata-typeattributes and points at the attacker's raw snippet. - The link's
hrefishttps://gitlab.com/-/snippets/1999974/raw, the attacker's raw snippet. Because it is on gitlab.com, the Content Security Policy permits it. - The markup includes an
<img width="10000" height="10000">element.
So the chain is: control the viewer URL, get your HTML into the page, and have that HTML contain a link that loads your JavaScript from the same site, which the browser's security policy allows. One click runs the code.
What the researcher did not finish
The researcher says they only skimmed the other places that use safe_params, and that a few more appear to load data via JavaScript or could be turned into open redirects. They also say they had not looked into whether the open redirects could be escalated to leak sensitive information, and would update the report if they found anything.
All the issues were put in one report because the fix is the same for all of them, with an offer to split them if the maintainers preferred. The severity was set to high because of how many places use the helper and how easy it is to trigger, while acknowledging that each individual issue is probably less severe and might need adjusting.
The root cause
The mistake is an incomplete deny list. safe_params removes only :host, :port and :protocol, while Rails recognises a much larger set of reserved options. Any of the remaining names that reach url_for are read as routing instructions rather than as ordinary data, so visitor input can change the scheme, the host or the path prefix of the generated URL. The method's name suggests it sanitises parameters, but it only covers three of the reserved names.
Impact
The report lists three impacts:
- open redirect on quite a few routes;
- reflected XSS using the
javascriptprotocol; - reflected XSS with a CSP bypass using the blob viewer.
The open redirect works on RoutableActions routes whenever the requested path differs from the canonical path, for example through a capital letter, and a domain parameter is supplied. The script_name XSS is reflected through generated links such as the RSS feed link, though on gitlab.com that variant is blocked by the CSP. The blob viewer variant achieves script execution despite the CSP by loading an attacker-controlled snippet as a script after a click. The researcher did not investigate whether the open redirects could be escalated to leak sensitive information.
The fix
The report states that SafeParamsHelper.safe_params should filter out all of the reserved options:
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
:trailing_slash, :anchor, :params, :only_path, :script_name,
:original_script_name, :relative_url_root]
Because the same helper underlies every variant, the report proposes this single change to cover them all.
Variants to test
If you want to look for the same class of bug elsewhere, these are the checks the report describes:
- Supply
domainon any route that goes throughRoutableActionsand make the requested path differ from the canonical path, for example with a capital letter. A positive result is a redirect whose host is the domain you supplied. - Supply
script_namewith ajavascript:scheme followed by//on pages that render links built fromsafe_params. A positive result is a generatedhrefbeginning withjavascript:. - Supply
script_namepointing at a URL you control that returns JSON with anhtmlattribute on the blob viewer. A positive result is your markup appearing in the page. - Try the other reserved options the helper does not strip, such as
subdomain,only_path,anchorandparams, whereversafe_paramsfeedsurl_for, and see whether the generated URL changes in a way you control.
Hunting notes
This kind of bug hides in helpers that try to clean up parameters before handing them to a framework's URL builder. The signal is a deny list that names only a few keys while the framework documents a larger set of reserved options. Comparing the two lists is usually enough to spot the gap. Once such a helper is found, search for its call sites: redirect builders, canonical path logic and templates that embed a URL in a data attribute are the most promising. The researcher showed impact by chaining the parameter into a redirect, into a generated link, and finally into an asynchronous viewer that inserts server-returned HTML. Grouping the findings under one report made sense because a single fix covers them all.
Glossary
- URL: the address of a resource on the web, such as
https://gitlab.com/page. - Query string: the
key=valuepairs after the?in a URL, carrying extra data to the server. - Parameter: one
key=valuepair in a request, whether in the query string or a form. - Ruby on Rails: a framework for building web applications in the Ruby programming language; GitLab is built with it.
url_for: a Rails function that assembles a URL from named pieces.- Reserved option: a parameter name Rails treats as an instruction for building a URL rather than as ordinary data.
- Helper: a small reusable piece of code, here one that prepares data for use elsewhere.
- Deny list: a list of things that are forbidden; it only protects against what it names.
- Open redirect: a flaw where a site can be made to send visitors to an address chosen by someone else.
- Canonical path: the one official spelling of a page's address.
- Case sensitive: treating uppercase and lowercase letters as different, so
Redirect1andredirect1are not equal. - GET request: the normal kind of request a browser makes when you open a page.
- AJAX / XHR: a request made by JavaScript in the background, without reloading the page.
- XSS (cross-site scripting): getting attacker-supplied JavaScript to run inside another website's pages.
- Reflected XSS: XSS where the malicious input is echoed straight back in the response rather than stored.
- JavaScript: the programming language browsers run to make pages interactive.
javascript:URL: a link whose address is JavaScript code, run when the link is clicked.- CSP (Content Security Policy): a browser rule set by a site that limits which scripts and sources a page may use.
- CSP bypass: a way of running script despite the policy, for example by loading it from a source the policy allows.
- Blob: a file stored in a Git repository.
- JSON: a plain text format for exchanging structured data between programs.
- Snippet: a small piece of shared code hosted on GitLab.
- Same origin: content served from the same scheme, host and port, which security policies often trust.
data-attribute: an HTML attribute used to attach extra information to an element for JavaScript to read.- DOM: the browser's in-memory model of the page, which scripts can read and change.
- Severity: a rating of how serious a vulnerability is.