Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for A tiny fix with big impact and high risk
Aleh Zasypkin
Aleh Zasypkin

Posted on • Originally published atsecutils.dev

     

A tiny fix with big impact and high risk

The original post was published on my blog onJuly 27, 2023, long before I realized it might be interesting to the dev.to community.

Hello!

Inmy previous post, I briefly touched on the latest1.0.0-alpha.2 release ofSecutils.dev. While the"Resources tracker" was the central part of this release, I want to highlight one tiny fix that makes a huge difference in user experience but can also be quite risky if not done right:“Recover original URL after sign-in”.

When you open a link to a web page that requires authentication, you are usually redirected to the login page. The most annoying thing that can happen is that after you enter your credentials and hit “Enter” you’reNOT redirected to your original destination! I see this issue more frequently on websites that require complex Single Sign-On (SSO) authentication flows, but it can also occur on sites with simple login flows. While it may be tolerable for one-time use links, it becomes a real pain if you need to use the link frequently or bookmark it.

Such behavior creates quite a bit of friction, distracting users from the action they wanted to perform initially. This drives users (myself included) crazy, and I don’t want to do that to Secutils.dev users.

There are different ways to approach this issue. The most common ones are to “remember” the original URL as a parameter in the login page URL to which the user is redirected, or to avoid redirect altogether by rendering a login modal/popup directly on the destination page. Both approaches have their pros and cons, but considering various corner cases with the login modal/popup approach, I generally prefer the separate login page for its simplicity and universality. As you might have guessed, I use this approach for Secutils.dev.

Now, let’s see how it works: If the user tries to accesshttps://secutils.dev/ws/web_scraping__resources but isn’t authenticated, the app will redirect them tohttps://secutils.dev/signin?next=/ws/web_scraping__resources. This way, the login page can extract the original destination page from thenext query string parameter and redirect the user to it after successful login. Is this that simple? Yes and no!

If we blindly redirect the user to whatever URL is embedded in thenext query string parameter, we run the risk of becoming an easy phishing target. Imagine someone shares the following link with you:https://secutils.dev/signin?next=%2F%2Fws-secutils.dev%2Fws%2Fweb_scraping. The main domain looks legit, and it’s not easy to notice that thenext parameter includes a URL to a completely different website -https://ws-secutils.dev/ws/web_scraping. Malicious actors can exploit various tricks and browser quirks to conceal the real destination in thenext parameter. For example, here I used a URL-encoded protocol-relative URL (// instead ofhttps://).

If Secutils.dev doesn’t validate the URL from thenext parameter properly, after successful login, you'll be redirected tohttps://ws-secutils.dev/ws/web_scraping, and the chances that you'll check the URL bar again are very low. This is known as an“open redirect”. Thehttps://ws-secutils.dev/ws/web_scraping page can look exactly like the login page of the legitimate website and can prompt you to re-enter your Secutils.dev credentials, tricking you into providing your login details on the wrong website. After it steals your credentials, it can finally redirect you tohttps://secutils.dev, and you might not even notice that something was wrong.

ℹ️ NOTE: Such phishing attackswouldn’t work if you use passkey as your credentials since it’s bound to the legitimate website/origin. If you don’t use passkey to sign in to Secutils.dev yet, I strongly encourage you to consider switching to it. It’s easy to do and convenient to use.

Phishing is much more common than you might think. Take a look at the image with the recent statistics:

Phishing statistics

The example above shows that you absolutely have to validate all URLs you redirect users to if there is a chance they can be manipulated by third parties. In the Secutils.dev Web UI, specifically, I rely on the nativeURL class to checkif the URL has the proper origin before redirecting the user. Also, check out"Preventing Unvalidated Redirects and Forwards" from OWASP for more tips.

I hope I showed that seemingly unimportant and easy fixes can not only have a significant impact on the user experience but can also put your users at risk if you don’t consider the security implications of such changes. It's crucial to be mindful of potential risks and carefully validate any modifications that involve user redirection to ensure the safety of your users.

That wraps up today's post, thanks for taking the time to read it!

ℹ️ ASK: If you found this post helpful or interesting, please consider showing your support by starringsecutils-dev/secutils GitHub repository.

Also, feel free to follow me onTwitter,Mastodon, orLinkedIn.

Thank you for being a part of the community!

Top comments(6)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
nicolus profile image
Nicolus
Hey, that's me !
  • Location
    Paris, France
  • Work
    Lead developer at Scutum Security First
  • Joined

Hi, nice write up (also I need to check secutils).

I've encountered this issue but I don't think "redirect after login" is where you're most at risk to find it for two reasons :

  1. It's pretty easy to secure (only allow redirections to your own domain). You donlt even need to do this at the application level : You can use your reverse proxy or WAF to inspect every response, make sure redirects are always the same domain as the request, and block everything else.

  2. I wouldn't even put this in the URL to begin with. I'd just store the intended route (not even the full URL) in a session so I don't have to pass it as a param from page to page if the user also has to create an account, validate it and so on.

Where I did encounter the issue is when some clients (in a b2b app) required us to redirect users to their users to a document on their own site (not ours) and keep track of who clicked the link. So we basically built a redirect route that would accept an url as a param, log that thebuser clicked the url and redirect them... And here we can't check that the domain is the same because it won't be. I think the best approach in this case is to do something like a url shortener : store the redirect urls in a database and just pass the id as a param (but you still have to either disable the reverse proxy rule I mentionned in point 1, or keep track of every authorized redirect domain and update the config accordingly).

CollapseExpand
 
azasypkin profile image
Aleh Zasypkin
Kibana Platform Security at @elastic • Open-source toolbox for security-minded engineers at http://secutils.dev • Free ETF research tools at http://azbyte.xyz
  • Location
    Berlin, Germany
  • Work
    Creator of the open-source toolbox for security-minded engineers - http://secutils.dev
  • Joined

Hey,

Thanks for the comment!

It's pretty easy to secure (only allow redirections to your own domain). You donlt even need to do this at the application level : You can use your reverse proxy or WAF to inspect every response, make sure redirects are always the same domain as the request, and block everything else.

Yep, in a simple case with a single deployment model, you can do that on the proxy level. However, you'd need to write an integration test against yourreal proxy to ensure your configuration works as expected after your initial setup. Otherwise, at some point, it will likely break during an upgrade, domain or sub-domain change, or some other proxy configuration refactoring. So, it might not be as cheap and easy as it seems at first.

The second reason to implement this on the application level is if you support multiple deployment models. For example, for Secutils.dev, I want to accommodate both on-premises setups (with or without WAFs, reverse proxies, etc.) and my own SaaS, where I do have a reverse proxy. In this case, I want Secutils.dev to work consistently everywhere and place as little deployment burden on on-premises users as possible.

I wouldn't even put this in the URL to begin with. I'd just store the intended route (not even the full URL) in a session so I don't have to pass it as a param from page to page if the user also has to create an account, validate it and so on.

It could work too, I think it's a matter of taste. I usually prefer not to create sessions (or any other server-side persistent data) for unauthenticated users to reduce the chance of unauthenticated DDoS attacks. You can add some acrobatics with client-side localStorage/sessionStorage, but using different mediums to store pieces of the session would be even more complicated.

And here we can't check that the domain is the same because it won't be.

I assume you also maintain a list of whitelisted domains on a per-customer/global level at least, right? If so, the attack surface might not be that big to seriously worry about it. Also, since we usually only care about security for users using browsers, a whitelist can also be bound to the HTTP Referer header (assuming the resources where links are located populate that header).

I think the best approach in this case is to do something like a url shortener

Yeah, that's another form of mapping based on whitelisted domains and outbound redirects.

but you still have to either disable the reverse proxy rule I mentionned in point 1, or keep track of every authorized redirect domain and update the config accordingly

That's another reason to consider doing this on application level, by the way.

CollapseExpand
 
heloisamoraes profile image
Heloisa Moraes
Digital Marketing Specialist with a passion for Tech
  • Email
  • Location
    Lisbon
  • Education
    PgD Marketing & Communications
  • Work
    Community Management at Codacy
  • Joined

Hey Aleh, cool project! In case you're interested, applications are still open to join the Codacy Pioneers, a fellowship for open source developers.

This program will fund, promote, and mentor innovative and creative OSS developers worldwide. The people selected will receive a year-long monthly stipend, free tools, widespread promotion, and mentorship from some of the brightest minds of today’s OSS community:

Vue framework creator Evan You;
Enix co-founder Jerome Petazzoni;
Prisma founder Johannes Schickling;
CHAOSS community lead Ruth Ikegah; and
Christoph Nakazawa, the creator of popular open-source tools like Jest, Metro, Yarn, and MooTools.

Head over tocodacy.com/pioneers to learn more.

CollapseExpand
 
azasypkin profile image
Aleh Zasypkin
Kibana Platform Security at @elastic • Open-source toolbox for security-minded engineers at http://secutils.dev • Free ETF research tools at http://azbyte.xyz
  • Location
    Berlin, Germany
  • Work
    Creator of the open-source toolbox for security-minded engineers - http://secutils.dev
  • Joined

Hey@heloisamoraes, I'll check it out, thank you!

CollapseExpand
 
michaeltharrington profile image
Michael Tharrington
I'm a friendly, non-dev, cisgender guy from NC who enjoys playing music/making noise, hiking, eating veggies, and hanging out with my best friend/wife + our 3 kitties + 1 greyhound.
  • Email
  • Location
    North Carolina
  • Education
    BFA in Creative Writing
  • Pronouns
    he/him
  • Work
    Senior Community Manager at DEV
  • Joined

Awesome-sauce! So glad ya decided to share this one with us, Aleh. 🙌

CollapseExpand
 
azasypkin profile image
Aleh Zasypkin
Kibana Platform Security at @elastic • Open-source toolbox for security-minded engineers at http://secutils.dev • Free ETF research tools at http://azbyte.xyz
  • Location
    Berlin, Germany
  • Work
    Creator of the open-source toolbox for security-minded engineers - http://secutils.dev
  • Joined

Glad you found it interesting and/or helpful!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Kibana Platform Security at @elastic • Open-source toolbox for security-minded engineers at http://secutils.dev • Free ETF research tools at http://azbyte.xyz
  • Location
    Berlin, Germany
  • Work
    Creator of the open-source toolbox for security-minded engineers - http://secutils.dev
  • Joined

More fromAleh Zasypkin

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp