I Hate CORS.

Поделиться
HTML-код
  • Опубликовано: 26 авг 2024

Комментарии • 306

  • @rubendacostaesilva8442
    @rubendacostaesilva8442 7 месяцев назад +257

    CORS was not a mistake. It was created to drive frontend engineers to insanity, and it accomplishes that to perfection.

    • @RaZziaN1
      @RaZziaN1 7 месяцев назад +17

      no need to drive them, frontend devs will do it by themselves

    • @btonez13
      @btonez13 7 месяцев назад +4

      see also: OAuth 2

    • @1Caja
      @1Caja 7 месяцев назад +1

      ​@@btonez13OAuth2 is great wdym?
      It's also easy to implement yourself either from documentations (Microsoft has some good ones) or from the RFC

    • @blatisgense933
      @blatisgense933 7 месяцев назад

      Omg literally me

    • @glaxmattbas
      @glaxmattbas 7 месяцев назад

      I believe all front-end tech has that goal

  • @arkuarku
    @arkuarku 7 месяцев назад +184

    It's more of a NextJS app router issue that you do no have a way to set common headers on the same URL for different http method. Most web-frameworks have CORS in mind and can let you easily setup CORS in some kind of middleware.

    • @samuellaycock4250
      @samuellaycock4250 7 месяцев назад +34

      Yeah. CORS is definitely a flawed spec, no doubt about it, but the “obnoxious” bit here is a Next thing

    • @MrRaitiz
      @MrRaitiz 7 месяцев назад +10

      Most definitely, it just shows how immature these JS frameworks for backend are. I mean its not end of the world as CORS is not THAT complicated. Also the preflight (OPTIONS http verb call) is meant for browsers to check the response headers so that the actual request can/cannot be sent, if can be sent then after the actual request browser checks that request response headers for the actual response.

    • @manikandanbalakrishnan7701
      @manikandanbalakrishnan7701 7 месяцев назад +4

      Oh yes these Js framework's are really immature, I did try to implement API using nextjs lots of issues like this. Java , phyton or c# is better for API development. I switched to remix for frontend from nextjs.... Much more flexible and uses unwrapped native node JS request and response.....

    • @monishbiswas1966
      @monishbiswas1966 7 месяцев назад +4

      @@MrRaitiz indeed, he key point about OPTIONS is that it guards against any side effects of the request, effectively to guard against a CSRF attack.
      Servers could guard against this by checking the CORS headers before carrying out the request, but it looks like the CORS spec takes a precautionary approach and assumes the server does not do this,
      The weird thing is the websocket spec takes the opposite approach and relies on the web sockets server to validate the Origin header within the app logic.
      I wonder how many webscketa servers do not check the Origin.

    • @asdf9833
      @asdf9833 7 месяцев назад

      I agree, this is a framework problem.
      On top of that, with server actions nextjs implemented an origin header check on the server. This is obnoxious part, instead of providing a good DX on top of a browser enforced CORS, they implement something else, that is much less flexible, adding another set of error messages to the pile. Have fun implementing a multi tenant app where users suppose to point their custom domain to your app. You’ll need to know all allowed hosts at build time AND still have to deal with CORS to prevent cross scripting issues between your tenants …

  • @SzaboB33
    @SzaboB33 7 месяцев назад +208

    I could say that the web is CORSed

  • @gergoradeczki
    @gergoradeczki 7 месяцев назад +127

    I hate that this video gives the impression that the problem is CORS, but in fact, the real problem is with Next.js.

    • @vaap
      @vaap 7 месяцев назад +2

      yea this video missed the mark soo bad, it comes off like Theo doesn't really understand what CORS solves.

    • @JEsterCW
      @JEsterCW 6 месяцев назад +1

      As always, i found out that vercel with next only makes problems 😂

  • @SergiobgEngineer
    @SergiobgEngineer 7 месяцев назад +186

    Most backend frameworks, like laravel or aspnet.core, deal with CORS gracefully.
    This is more of an issue with nextjs than any other thing.

    • @GamePlayByFaks
      @GamePlayByFaks 7 месяцев назад +5

      that won't solve node.js cor's issues :D

    • @fnfal113
      @fnfal113 7 месяцев назад +3

      @@GamePlayByFaks fun fact cors package is configurable on nodejs

    • @GamePlayByFaks
      @GamePlayByFaks 7 месяцев назад

      @@fnfal113 let's be real not everybody add's packages to handle cor's that's just reality of it, since dependency hell on nodejs all ready is a thing...
      Note:
      Also don't forget not everybody use latest and greatest stuff around, like we have spa vue.js v1.x with node.js that is a bit outdated, so each time is a gamble.

    • @proosee
      @proosee 7 месяцев назад +45

      Thank you, exactly what I wanted to say. Nodejs logic: "we can't write proper code to handle a web standard or copy solution from other technologies" = "web standard is stupid". Guys, just look how it is done in other frameworks, why do JS devs need to invent everything again from scratch?

    • @shacharronzohar6960
      @shacharronzohar6960 7 месяцев назад +1

      @proosee
      ​because node isn't a framework, it's an engine to run JS outside of the browser.

  • @Luxalpa
    @Luxalpa 7 месяцев назад +65

    I just want to point out, when watching your video in slow motion, at 5:52 when you close the image it is possible to read your X-Uploadthing-Api-Key. Thought you might want to fix that and reupload (or change the key).

    • @t3dotgg
      @t3dotgg  7 месяцев назад +62

      Ty for heads up, thankfully that key hasn't been valid for over 2 months lol

    • @ninjaasmoke
      @ninjaasmoke 7 месяцев назад +2

      why were you watching it in slow motion? 😂

    • @dennis_benjamin
      @dennis_benjamin 7 месяцев назад +22

      @@ninjaasmoke People who are into security look very closely whenever somebody streams code. That black box redacting something which than moves behind that block is just asking to be checked out frame by frame 😂

    • @wil-fri
      @wil-fri 6 месяцев назад +1

      @@ninjaasmoke there have been cases of filtering of... fingerprints or other codes. Wikipedia was requested to remove the FBI badge at wikimedia

  • @itsfolf
    @itsfolf 7 месяцев назад +36

    CORS is handled by the browser, the client needs the OPTIONS request to know whether or not the POST request is allowed, you're inflicting this pain upon yourself by hardcoding cors rules in javascript on different method calls, cors is supposed to be handled by the web server itself

    • @frydegz
      @frydegz 7 месяцев назад +6

      web people don’t actually understand how the web works

    • @Mooooov0815
      @Mooooov0815 7 месяцев назад

      Except for that not every request does need an option preflight request. As long as your request qualifies as a „simple request“ (specific content types and no non standard headers, etc) your browser will not issue a preflight request, but the response still needs the proper cord headers present

    • @jimbolino
      @jimbolino 7 месяцев назад

      @@Mooooov0815 the "simple" requests are there for backwards compatibility reasons. GET calls with no additional headers (same as embedding an IMG tag in your document) or POST requests that do a simple application/x-www-form-urlencoded plain old form stuff.

    • @itsfolf
      @itsfolf 7 месяцев назад +1

      @@Mooooov0815 If the request does not cause a modification on the server (i.e. GET), then it does not need a preflight, because you can simply filter when the response comes. But for a request that causes a modification on the server (i.e. POST), filtering on the response would be too late, so you need to check first.

  • @nikolaberovic2044
    @nikolaberovic2044 7 месяцев назад +56

    Problem is that web devs should learn fundamentals, and why we have CORS, and how to address these issues in non security threatening way. Most of devs solve it by allowing all origins, which intoduces many security risks.

    • @31redorange08
      @31redorange08 7 месяцев назад +12

      The Twitter replies shown in this video are enough to conclude that people have no idea what they are doing.

    • @nikolaberovic2044
      @nikolaberovic2044 7 месяцев назад

      @@31redorange08 what is worse is that many devs working in big companies do not know either. Since web dev became an industry, real knowledge has declined.

    • @phillipgilligan8168
      @phillipgilligan8168 7 месяцев назад +6

      Agreed allowing all in prod is NOT a solution.

    • @vintagewander
      @vintagewander 7 месяцев назад +5

      the entire video itself is just web dev skill issues

    • @mwcavanagh
      @mwcavanagh 7 месяцев назад

      Productive devs vs senior devs problem right there. @@phillipgilligan8168

  • @DryBones111
    @DryBones111 7 месяцев назад +11

    I disagree wholeheartedly with this. CORS is not flawed, next.js is flawed. The only time I've ever been caught out by CORS is when I forgot to configure CORS middleware. One commit later and there are no more issues. Use proper tooling for APIs and you won't run into half these issues.

    • @user72974
      @user72974 7 месяцев назад +2

      Agree. CORS is basically a way for you to opt into which domains are allowed to interact with your server. How is that a bad thing? Complaining about CORS existing is like complaining about passwords existing. Would you be angry that passwords exist to allow you to opt in to who is able to access your accounts (if you even choose to allow this)? I doubt it. And from the other perspective, for those front end apps running in the browser on various domains out there, it was a backwards compatible way to make sure sensitive data wasn't being transmitted to 3rd party domains. Security by default is a good thing. The fact they added cross-domain AJAX support in a backwards compatible way like this is impressive.
      I do realize it can feel complex to people who've never worked with it before. And that complexity can be magnified when you're working with a 3rd party thing (like this video creator is) who is also doing something complex, like running things meant to be run on servers in the browser. Now you're at the mercy of how that 3rd party works. But you've always got the freedom to choose to simply not use that service.
      Anyone new to CORS who is frustrated with it should use the same solution they've probably found successful so far when dealing with new things. If it's too complex, provide feedback to its creators so they can simplify it (CORS probably cannot be simplified any further) and then try as hard as you can to learn it. MDN has great resources for learning how CORS works.
      One more tip I'll leave for people... embrace proxying if you need it. It's not the evil, dirty workaround it might seem to be. Browsers have no way to know that two domains are owned by the same party, so they have no way to trust a different domain when a request is being made to it. If you proxy the requests you want your app to make, hosting the proxy on your domain, the browser doesn't have to worry about this. You're vouching for that service to the browser. It simply makes another call to your domain, like it's doing for every other call to your backend. This doesn't even have to be a separate application. It can just be another route in your back end application if you want.

  • @SanderCokart
    @SanderCokart 7 месяцев назад +22

    This is why cors in laravel is global or per route or both. It's awesome. Makes cors easy

    • @GamePlayByFaks
      @GamePlayByFaks 7 месяцев назад

      Laravel has built in package to handle that but if you have outer api for spa or whatever then that solves only one way not the other from node.js

    • @SanderCokart
      @SanderCokart 7 месяцев назад

      @@GamePlayByFaks i meant cors.php in config folder

    • @GamePlayByFaks
      @GamePlayByFaks 7 месяцев назад

      @@SanderCokart okay.

  • @Hexalyse
    @Hexalyse 7 месяцев назад +44

    I think devs who hate CORS are devs who still didn't fully understand what CORS are for and how they work. I mean, what is there to hate, once you get them ? Security ? Isn't it a GOOD thing ?

    • @Rust_Rust_Rust
      @Rust_Rust_Rust 7 месяцев назад +12

      You can hate something that is difficult to work with even if that added difficulty is a net good.

    • @renatolovato
      @renatolovato 7 месяцев назад +2

      wow did you say it? I agree! Also, you should never set Access-Control-Allow-Origin = *, unless your API is meant to accept requests from unknown sources.

    • @Hexalyse
      @Hexalyse 7 месяцев назад +4

      @@Rust_Rust_Rust Ok, I can agree. But CORS couldn't be more simpler. I'd even argue its failure is to be too simple : for example being able to only declare one domain as an allowed origin. They could have allowed you to just send back a coma separated list.
      But I don't see how CORS is "difficult to work with". It's a bunch of headers that tells a browser what methods it can use and from what domain, for a certain URL. Nothing more.

    • @TheNewton
      @TheNewton 7 месяцев назад +4

      @@Hexalyse lol lol arguing it's too simple while pointing out a main cause of why it's not simple. LOL 🤡🤸

    • @codewithwings
      @codewithwings 7 месяцев назад +1

      @@TheNewtonI'd like to see him hook up a front end to an API he hasn't worked with before on a live stream. If you think CORS couldn't be "more simpler", either you're amazing, or don't code very much.

  • @RupluttajaGames
    @RupluttajaGames 7 месяцев назад +26

    Skill issue

    • @matthewvanderwesthuizen162
      @matthewvanderwesthuizen162 7 месяцев назад +8

      I was just about to say. This is no more than a skill issue. Dont't be hating on stuff that increases security and safety on the net.

    • @31redorange08
      @31redorange08 7 месяцев назад +1

      The only reasonable comment here.

  • @tacticalassaultanteater9678
    @tacticalassaultanteater9678 7 месяцев назад +17

    There are two kinds of webdevs, those who hate CORS and those who can read a full MDN page to understand something.

  • @DavidMulderOne
    @DavidMulderOne 7 месяцев назад +11

    This video would've been better by mentioning *why* the OPTIONS request exists and why websockets don't use CORS. If the OPTIONS pre-flight request wasn't there then the browser would still have to execute the request against the actual endpoint, and the endpoint would still do 'the thing it is supposed to do' (e.g. delete all your files). The OPTIONS call is an 'innocent' call that has 'no' risk of having any side effects. Whether the required confirmation on the actual resource is or isn't beneficial enough in the grand scheme of things I agree can be debated, but frankly in no project I ever did different resources have different CORS responses, so I always just threw it in as some type of quick middleware on all routes which took me all of 5 minutes. Obviously the more complex your architecture is, the less true the 5 minute statement becomes (e.g. in one architecture setup I 'helped out with' (just giving advice) they had to dynamically sent the list of allowed servers to the API server which then had to add them to the CORS list, but that was a pretty crazy setup). As to why websockets don't require CORS: The argument goes that if the web was invented today we wouldn't have CORS nor the same origin policy and instead checking the Origin header would simply be left to the server. As websockets were invented 'late enough' in the web's development the argument goes that there is no risk of legacy servers to be concerned with, so leaving the check to webservers directly is simply more efficient.

    • @RaZziaN1
      @RaZziaN1 7 месяцев назад

      " instead checking the Origin header would simply be left to the server." - im pretty sure that's how it is anyway.

    • @DavidMulderOne
      @DavidMulderOne 7 месяцев назад

      @@RaZziaN1 The point is that for normal HTTP calls that's *not* the case right now, just for websockets as those are new.

    • @monishbiswas1966
      @monishbiswas1966 7 месяцев назад

      ⁠@@RaZziaN1 not quite - most properly written websites would have CSRF protection jest originated from the same request, but as the Origin header is recent and not sent on all requests it would probably not be checked at all

    • @TheNewton
      @TheNewton 7 месяцев назад

      ...because backwards compatibility minutiae is piling up saddling modern web development with past bad decisions.

    • @pawelparadysz
      @pawelparadysz 7 месяцев назад

      @@DavidMulderOne but I can just extract the origin, validate it, and set the cors to allow it? or am i missing something?

  • @Liz3_
    @Liz3_ 7 месяцев назад +5

    I can't understand where the issue is here? CORS is well dcoumented and super important.
    The preflight request happens because of the way http works, which means the browser doesn't want to send the actual request before asking the server, hey is this okay.
    And then it makes total sense it RE-verifies it on the actual request.
    This makes sure a clien't cant request a server if the server is limited to a specific origin.
    Regarding the sockets thing, http works over tcp sockets? So cors is only concerned with the content of the http request and doesnt care about anything below it.
    Further the argument: i had to write the headers twice, have people forgot something called middleware exists?
    I can understand it can be frustrating, but it seams this is more because the concept of cors wasn't understood rather then cors actually being wrong.

    • @monishbiswas1966
      @monishbiswas1966 7 месяцев назад

      I think when he said sockets he meant websockets, which does not need CORS to go cross domain - instead the server is supposed to validate the Origin header.
      The reason CORS has a preflight request is because some web endpoints may predate CORS and not know to check the Origin header, and would be vulnerable.

  • @TheJubeiam
    @TheJubeiam 7 месяцев назад +8

    Dam there are like 3 rules to support CORS its really not that hard.
    Second thing dont support CORS in your app, but in your infrastructure

    • @renatolovato
      @renatolovato 7 месяцев назад

      Yes, you're absolutely correct. Unless the application needs to dynamically set the allowed source based, for example, on the user authenticated, you should deal with CORDS on Nginx, Apache, etc.

  • @kamiljanowski7236
    @kamiljanowski7236 7 месяцев назад +9

    This is pain. But you know what's even more painful? The fact that you don't have canary deployments for stuff that you know might fail due to a developer's mistake

  • @youngsinatra2916
    @youngsinatra2916 7 месяцев назад +23

    I'm currently building my first real full stack app and I'm currently facing exactly this problem lol, thank you Theo for hearing out my soul always

  • @itamarsharify
    @itamarsharify 7 месяцев назад +34

    This video convinced me CORS should stay the same. They guard you from this messy approach

  • @3ventic
    @3ventic 7 месяцев назад +16

    Before CORS it was common to see the session or CSRF token in the URL for pages with potentially sensitive content that was server-rendered. It was a much bigger pain both as a developer and a user (couldn't just copy URL to send to a friend or colleague since it was unique to your session and sometimes to that specific page-access). Perhaps there's a 3rd option that would be better, but comparing to the way websockets did it for example: I think it's simpler for web servers to set one (sometimes you need the others, but in my experience it's rare) headers on the endpoints, where cross-origin is OK, than to check the origin header on every endpoint that may have sensitive data. The header can be set by the edge server, whereas the origin checks usually have to live in the application code.

  • @leonardsam7083
    @leonardsam7083 7 месяцев назад +7

    In my recent battle with CORS, I just slapped some "no cors" in there and called it a day

  • @x.d.hazard
    @x.d.hazard 7 месяцев назад +1

    damm, i was dying fixing cors errors for 2 hours just 30 min ago

  • @olhoTron
    @olhoTron 7 месяцев назад +3

    I work on a legacy system, and someone was trying to add a more modern API (the new code is somehow worse than the old, but that is a tale for another day) on a separate domain, and strugled for days with CORS, I was like "come on, we are behind a reverse proxy, just put the API on the same domain with a url prefix" and everybody was happy ever after... except when someone needs to touch the new code

  • @quadmasterXLII
    @quadmasterXLII 7 месяцев назад +5

    Consider writing a server that, after recieving a request, queries a database and then serves html

  • @essamal-mansouri2689
    @essamal-mansouri2689 7 месяцев назад +3

    Honestly stuff like this is where having an API gateway and a proper deployment process where you can set rules like CORS and authentication as part of your infrastructure code instead of putting it in your javascript like you were doing in this video.

  • @nsk8ter524
    @nsk8ter524 7 месяцев назад +2

    CORS or and TLS specific code shouldn't be written in node. That is the only problem here.

  • @ankitjain9070
    @ankitjain9070 7 месяцев назад +2

    Let's talk solutions. When you're stuck on a CORS issue and need a quick fix, there are tools out there to help. Beeceptor, for example, is a lifesaver. It's this cool HTTP proxy that handles CORS smoothly, adding required headers to the original API response. Frontend/Javascript devs looking to get past those annoying CORS blockers, a time saver!"

    • @himanshuvora1980
      @himanshuvora1980 7 месяцев назад

      Let us connet, I would like to test my online voting solution API .

  • @rflsms
    @rflsms 7 месяцев назад +6

    I always hated CORS, it seems like reinventing cookies would be a smarter move… Anyway, thanks for the video! Letting you know that the screen is flickering on darker tones like in 4:50. I thought there was a problem with my tv hahah

    • @RaZziaN1
      @RaZziaN1 7 месяцев назад +1

      no issue with flickering for me

    • @rflsms
      @rflsms 7 месяцев назад

      ​@@RaZziaN1its very subtle, I can see it in my tv and phone very well, but it is harder to spot on my monitor (I can still see it though, but it is definitely not as annoying as on my tv, probably due to local dimming)

  • @samuelgunter
    @samuelgunter 7 месяцев назад +8

    its improperly named, it should be called CORB: Cross-Origin Resource Blocking because thats all it seems able to do

    • @31redorange08
      @31redorange08 7 месяцев назад

      No, you apparently don't understand CORS.

  • @jamesgregor9614
    @jamesgregor9614 7 месяцев назад

    "I FIXED IT"
    "I did not fix it."
    Yeah, sounds like cors.

  • @rodrigo64703
    @rodrigo64703 7 месяцев назад +3

    They don't want some website making requests to another website because cookies are sent by default, so by default, those requests could be authenticated. The solution was to list all websites that are allowed to make such requests. In my opinion, an easier solution would be to just not send the cookies in those cases instead of blocking the request. Sometimes you just want to make an unauthenticated request to a different domain and with the protocol we have now, you need to proxy the request to work around CORS. If you are just writing some html to run from the file system. You also don't get to do requests so you always have to spin a small web server. But it is too late to change how this works now. Maybe in the future with new protocols we won't have this problem anymore. I'd rather start from scratch than patch this in a way that won't break older pages.

    • @monishbiswas1966
      @monishbiswas1966 7 месяцев назад

      The issue with this approach is that if the victim is on an internal network it would allow access to internal services through a malicious websites.
      The localhost restriction is probably there for a good security reason as well

  • @eatenpancreas
    @eatenpancreas 7 месяцев назад +2

    I still will not forget the time i was learning laravel in my internship. For some reason, failed user validation in the backend would result in a CORS error. I had to figure out everything on my own. A fucking hellhole that was.

    • @jimbolino
      @jimbolino 7 месяцев назад +1

      error pages usually dont emit the correct cors headers

  • @FranFiori94
    @FranFiori94 7 месяцев назад +1

    Cors is pretty straightforward, clear lack of skill by junior devs, been there

  • @josefaguilar2955
    @josefaguilar2955 7 месяцев назад

    I love watching real world debugging. I think getting a peek into the mindset of somewhen when fighting issues is so important. So much of this work is about solving the right problem and checking the right things and not digging yourself deeper. Its also an extremely personal process.
    Thanks as always for sharing.

  • @haithem8906
    @haithem8906 7 месяцев назад +1

    If you don't use cookies
    Leave cors open

  • @poggybitz513
    @poggybitz513 7 месяцев назад +1

    I've literally never had an issue with CORS. I actually love that cors exists so I can deny malicious attackers. :D CSRF was so much pain to integrate and handle than cors, which I still have to do sometimes and make things work.

  • @HumphreyMurray
    @HumphreyMurray 7 месяцев назад +1

    CORS is complicated & confusing, BUT PRETTY MUCH ESSENTIAL to prevent malicious websites doing bad things! I'm convinced that it needs to be what it is and work pretty much how it does. Use a good library (such as django-cors-headers) and just enable what needs to be allowed. I think what is confusing about CORS is it the browser restricting what the client can do, whereas normally it's the server restricting what the client can do.

  • @EngineerNick
    @EngineerNick 7 месяцев назад

    CORS: an ordeal every time

  • @RayAndrewsDev
    @RayAndrewsDev 7 месяцев назад +2

    I feel like I've just been to a successful support group meeting :)

  • @sparklitd
    @sparklitd 7 месяцев назад

    CORS is a true nightmare, lol! A labyrinth within a maze!

  • @kalvinpearce
    @kalvinpearce 7 месяцев назад +1

    Only calling it Cross Origin Request Stuff from now on

  • @shadowpenguin3482
    @shadowpenguin3482 7 месяцев назад +1

    At 5:36 you leak a few character from the key, definitely not enough to access something but maybe still a good reason to recreate it

  • @Jenkkimie
    @Jenkkimie 7 месяцев назад

    It's frustrating when I am a junior developer who is trying to learn fullstack and suddenly you get CORS-policy violation. You have no clue what it means, what causes it and how to fix it. All you know is suddenly your app isn't working anymore. Good luck!

  • @kcin4206
    @kcin4206 5 месяцев назад

    Currently smashing my head into my keyboard because of CORS, surprised the keys still work well enough for me to type this.

  • @Jabberwockybird
    @Jabberwockybird 7 месяцев назад

    That CORS frustration you got there is pretty cool. It would be a shame if someone
    MADE A SERVER-SIDE PARTNER TO IT CALLED XSRF-CSRF
    🤬🤬🤬🤬

  • @SeattleSpursFan1882
    @SeattleSpursFan1882 7 месяцев назад

    So let's fix it. How would we start doing that?

  • @seephor
    @seephor 7 месяцев назад

    CORS should be a turn on feature rather than a turn off feature

  • @donwinston
    @donwinston 7 месяцев назад +1

    Couldn't you write a rule implemented as a function or class that encapsulates all of this in one place?

  • @tdiblik
    @tdiblik 7 месяцев назад

    "WE SHOULD NOT BE HERE, CATCH YOUR FAILURES EARLIER" xddd

  • @joseeavr
    @joseeavr 7 месяцев назад +1

    senior engineer and don't know how to deal with CORS?

  • @Bliss467
    @Bliss467 7 месяцев назад +3

    I’d love to hear about conceptual alternatives

    • @npc-drew
      @npc-drew 7 месяцев назад

      At the time, I thought since running Node JS could circumvent CORS, I found StackBlitz, to run WebContainers with NodeJS, maybe this could get away too, but this always stayed a theory.

    • @DarrenJohn10X
      @DarrenJohn10X 7 месяцев назад

      MeToo

    • @jimbolino
      @jimbolino 7 месяцев назад

      csrf token that rotates after every request

  • @YourConsole
    @YourConsole 7 месяцев назад +1

    I hate to take this stance, and sound like Prime, but this seems like a skills issue. Setting up an endpoint to respond with the same CORS headers for OPTIONS or POST/GET without copy-pasting the code isn't hard.
    I understand that backend code running in the browser needs work to adhere to CORS, and I totally get how "wait my requests are running in the browser now" wouldn't necessarily occur to a dev immediately. But I feel like if you sit down and understand CORS these things become apparent and reasonable pretty quickly.
    The OPTIONS preflight is an effort to avoid server-side actions that the client can't read the result of. But the CORS checks still need to pass on the actual request for the browser JS to get access to the response (but you'll see the request did actually happen if you look at the server).

  • @TheAlphaGames
    @TheAlphaGames 7 месяцев назад

    I work at a billion+ dollar company and we had some CORS related problems last week. It wasnt that CORS was blocking anything its just that our logs in datadog went from a few hundred thousand to over 2million overnight when we launched a new product because the new product had a new service that talked with our core service and every request was hitting a CORS check. So I figured out we should just set Max-Age on the requests so CORS can effectively f-off for at least for some time. And then I learned that the max-age DIFFERS FROM BROWSER TO BROWSER.
    I hate CORS.

    • @DimkaTsv
      @DimkaTsv 7 месяцев назад

      Does it differ in between different versions of same browser though?
      Just wondering, because knowing world of developers it could very well be so.

  • @rapzid3536
    @rapzid3536 7 месяцев назад

    BFF is your best f****** friend. Pre-flights add significant extra latency, particularly if paying the Cloud Flare latency tax, and it's particularly bad for some users; like international.
    Serve your FE from the same origin as your API.

  • @avishjha4030
    @avishjha4030 7 месяцев назад +4

    This is kind of a Next problem rather than a CORS problem.

  • @Engazan
    @Engazan 7 месяцев назад

    yea that "prefab" OPTION calls took us few hours too :D, and fixed only because we tried normal ajax and not fetch where you see "prefab" request in network ...

  • @eppiox
    @eppiox 7 месяцев назад

    It was definitely written by those esoteric programmers who are like 'read the manual' instead of making it good. I wonder how many millions of dollars they have cost in lost time.
    Almost as bad as certificates, just recently the windows 22H2 update made some sites use TLS1.3 ... which broke. good times.

  • @kriptxnic
    @kriptxnic 7 месяцев назад +1

    i’ve never clicked on a video so fast

  • @VaibhavPathak-fj6xy
    @VaibhavPathak-fj6xy 7 месяцев назад +5

    CORS is a pretty good standard, I don't think it's a problem because of CORS, it's more about how the browser implements it and also does it allow you to pass your own preflight info or an API call. One of reasons why I don't like front-end development because it's mostly your browser and also some browsers gives stuff like blocking these kind of cases. If you deal with them you will hate CORS more than anything. Sometimes same happens with cookies too.

  • @IceQub3
    @IceQub3 7 месяцев назад

    The reason why cors is not enforced on websockets is because websockets requests results in a 101 and have no body.
    CORS is not an attempt to protect the origin site but the foreign resource itself, like images and what not.
    This enable backends to protect against malicious websites running on genuine user browser.
    Its pain because the server software you use is bad, but hating on cors is like hating on tls.

  • @martinkinywa2512
    @martinkinywa2512 7 месяцев назад

    In my 20 years of coding, for the backend, I have used Sping (JAVA), Laravel (PHP), Symfony (PHP), .NET, Django (Python), Flask (Python), Gin (Go). CORS has never been an issue and I have dealt with it more times than I can count. CORS was well designed and thought out and all the frameworks I have mentioned deal with it nicely. This video is nothing but a NEXTJS problem!! And the bigger picture is that javascript should have stayed in the browser!

  • @CodeReign
    @CodeReign 7 месяцев назад

    You shouldn't write cors in your request handler. Cors should probably be in a filter somewhere

  • @blessedpigeon6304
    @blessedpigeon6304 7 месяцев назад

    actually the biggest problem with cors in my opinion is that i've read countless explanations and still not sure why the fuck do we need this in the first place

  • @seephor
    @seephor 7 месяцев назад

    The funny part of this is you can just put the API calls behind a server and bypass CORS all together. In other words, the only nefarious actors thwarted by CORS are the lazy ones who want to just use a cross origin resource by copy/pasting a URL into their source.

  • @Shaunmcdonogh-shaunsurfing
    @Shaunmcdonogh-shaunsurfing 7 месяцев назад

    I feel like this is a CORS + BROWSER issue

  • @ownerAccount
    @ownerAccount 6 месяцев назад

    Not sure if you noticed but your (duplicated) cors headers code is out of sync ;) in options your settings are different than in post ;) Just like you said in the video (different methods listed ;) )

  • @Leto2ndAtreides
    @Leto2ndAtreides 7 месяцев назад

    I remember the OPTIONS headache - and different implementations in different browsers.

  • @Daniel15au
    @Daniel15au 7 месяцев назад

    CORS is way better than the hacks we used to have to do (like JSONP). The issue is your framework.

  • @Toleich
    @Toleich 7 месяцев назад

    CORS feels like a Microsoft API from 8 years ago.

  • @2547techno
    @2547techno 7 месяцев назад

    isnt this a reupload? or am i not remember right

  • @Fomoerectus-wu1xefom
    @Fomoerectus-wu1xefom 7 месяцев назад

    I suggest we call it kors as in causing korsakov

  • @riolly
    @riolly 7 месяцев назад

    Listening is already so complicated, could you imagine dealing with these?

  • @yajirushik2871
    @yajirushik2871 7 месяцев назад

    Cors are easy, I have been able to learn about them perfectly after dealing with errors related to them for few days, after that it's easy.

  • @Not_Aran8276
    @Not_Aran8276 7 месяцев назад

    Hello world

  • @EdwinMartin
    @EdwinMartin 7 месяцев назад

    “Cross Origin Request Stuff” 😄

  • @AnsisPlepis
    @AnsisPlepis 7 месяцев назад

    It gets even worse when the headers get cached during development. Oh boy does it get worse…

  • @chrisalexthomas
    @chrisalexthomas 7 месяцев назад

    argh, I feel this pain, I wouldn't piss on cors' burning body...it's always a pain in the neck

  • @asdion
    @asdion 7 месяцев назад

    I as a user should be able to disable cors as easily as i can disable "Enhanced tracking protection"
    Not being a "webdev" my foray into dealing with js and cors has been complete hell (mainly getting data from apis i do not own like weather data that don't provide a way to deal with cors)
    The only good thing cors has done is to push me to just do all of that garbage on a local server and simply serve the data that way instead of having the "application" run within the browser

  • @nirnullz
    @nirnullz 7 месяцев назад

    It’s more about lot of the framework don’t have custom cors setting by deployment profile by default or it’s not flexible enough it’s so rigid nothing can be customized. It’s make developer need to setup cors header and OPTION manually in hacky way like demonstrated on this video.
    The easiest way to solve it in production is by using proxy server or api gateway to make all the cors setup centralized on one place.

  • @Shogoeu
    @Shogoeu 6 месяцев назад

    Yeah, that's what you get for being spiteful about other's misfortune.

  • @davidwang7489
    @davidwang7489 7 месяцев назад

    Why do you include Access-Control-Request-Method in the server code? That's just a header sent by the client during the OPTIONS pre-flight. I would remove that in cases it causes problems with some clients. Some clients are really picky about stuff (like Access-Control-Allow-Methods did not allow wildcards in the past). There's a lot of subtleties as you get into edge cases with credentials and allowed request headers. Even re-reading through my implementation for work just now, I realized my own implementation is not quite correct because for my OPTIONS response, I send back the origin requested in "Access-Control-Allow-Origin", but because I do that, I should add a "Vary" header specifying that so that any intervening proxies do not cache the "Access-Control-Allow-Origin" response just for that particular asked for origin.

  • @FanatiQS
    @FanatiQS 7 месяцев назад

    I made a cross origin POST request to my own custom HTTP server. I got the request and parsed it correctly, but the browser refused to hand over the response because of CORS. What does that help? I have already processed the request on the server and sent a response knowing the source of the request. I know I can add some headers to allow access to the browser, but why? The server has decided to not reject the request, shouldn't that be enough?

  • @Kotfluegel
    @Kotfluegel 6 месяцев назад

    Honestly, I'd rather deal with CORS, than trying to wrestle wth nx, typescript, babel and webpack.

  • @GearsDatapacks
    @GearsDatapacks 7 месяцев назад

    We all hate CORS.

  • @truvc
    @truvc 7 месяцев назад

    My most popular stackoverflow question and answer are about CORS

  • @unixrebel
    @unixrebel 7 месяцев назад

    I gave up trying to get CORS working while having my entire app in docker containers in development.

  • @codedusting
    @codedusting 7 месяцев назад

    Partytown with GTM has this issue. I don't control GTM backend so how to solve it even 😂?

  • @LoveLearnShareGrow
    @LoveLearnShareGrow 7 месяцев назад

    My service just returns the exact same cors headers on every single request. Does Next not have a middleware setup like Express?

  • @tiborsaas
    @tiborsaas 7 месяцев назад

    You also "have do deal with" seatbelts if you drive anywhere :)

  • @ryangrogan6839
    @ryangrogan6839 7 месяцев назад

    I actually had a cors issue today. Found an easy fix though, thankfully.

  • @reed6514
    @reed6514 7 месяцев назад

    Man, you gotta take a break when you're stuck on a bug that long. It's always easier to fix with a clear head the next day.

  • @lcarsos
    @lcarsos 7 месяцев назад

    But, you're Theo, not Frank.

  • @davivify
    @davivify 7 месяцев назад

    With all those 'options calls' I hope strike it rich in the stock market. Good luck with your CORS correction.

  • @bawbsmith
    @bawbsmith 7 месяцев назад

    O B N O X I O U S

  • @bioshazard
    @bioshazard 7 месяцев назад

    LOL I ran into the OPTIONS issue when trying to make an OpenAI Compatible Endpoint... the things you learn trying to make a server...

  • @abiodun6897
    @abiodun6897 7 месяцев назад +1

    Nothing pisses me off than constipated facial expression for a thumbnail 😩

  • @stefankracht
    @stefankracht 7 месяцев назад +2

    My favourite „solution“ for Development landed in Chrome a couple of months ago. Overwriting response headers like setting Access-Control-Allow-Origin to *
    ruclips.net/video/e8tl_yp5BQg/видео.html

    • @nikolaberovic2044
      @nikolaberovic2044 7 месяцев назад

      So many answers on stack overflow do the same... Which is a pity.. always try to understand why things happen

  • @dogoku
    @dogoku 7 месяцев назад +1

    There's also the fact that if you want to send credentials (i.e cookies) with a request, you can't use "*" in your allow origin header. The server needs to respond with the correct origin for each request. Because reasons

  • @Buffalo93
    @Buffalo93 6 месяцев назад

    Looked interesting, but there are barely any arguments in the video on why CORS were a bad idea. I get that it's inconvenient, but so is basically any other security measure.

  • @Tonaldo90
    @Tonaldo90 7 месяцев назад

    We all do, brother, we all do.