how to handle buckets safely
learn13-tech
FREEOP

7 hours ago

does this mean that I have to buy a separate domain for hosting images and point it at Railway ?

"One class of attacks can be prevented by always serving user uploaded content from a distinct top-level or second-level domain. This prevents any exploit blocked by same-origin policy protections such as cross site scripting. For example, if your site runs on example.com, you would want to serve uploaded content (the MEDIA_URL setting) from something like usercontent-example.com. It’s not sufficient to serve content from a subdomain like usercontent.example.com. "

quote from official django framework docs: https://docs.djangoproject.com/en/dev/topics/security/#user-uploaded-content

does this force me to buy a domain just for railway buckets ?

Awaiting Conductor Response$10 Bounty

22 Replies

Railway
BOT

7 hours ago

This thread has been opened as a bounty so the community can help solve it.

Status changed to Open Railway about 7 hours ago


manuproject
HOBBYTop 5% Contributor

6 hours ago

no, you don't need to buy anything for this. railway's bucket storage already lives on its own domain (storage.railway.app), completely separate from your app's domain, so serving uploads from there already satisfies what those django docs are asking for, details here:

https://docs.railway.com/storage-buckets

one thing to know though: railway buckets are private by default, no public url. you serve files either through presigned urls or a small proxy in front of the bucket, there's a ready-made template for that here:

https://railway.com/deploy/public-bucket-urls

either way the traffic goes through railway's domain, not yours, so you're covered without buying a separate domain.


learn13-tech
FREEOP

6 hours ago

but my main app is already on railways domain tho


learn13-tech
FREEOP

6 hours ago

and they say that stuff like this will not work

"from something like usercontent-example.com. It’s not sufficient to serve content from a subdomain like usercontent.example.com."


learn13-tech

and they say that stuff like this will not work "from something like usercontent-example.com. It’s not sufficient to serve content from a subdomain like usercontent.example.com."

The docs here are talking about serving users' assets from your own app, that's why they are recommending using a secondary domain for that purpose. Using buckets is already suggested as a safe alternative to this approach in the Django docs.

Buckets do not require custom domain setup, your backend communicates with the bucket and generates presigned URLs so you can provide to users and they can access their assests.


learn13-tech
FREEOP

6 hours ago

interesting to me it seemed like they said that

  1. buckets need to be public instead of private
  2. buckets need to be on a different domain than the main app

learn13-tech

interesting to me it seemed like they said that 1. buckets need to be public instead of private 2. buckets need to be on a different domain than the main app

  1. You can configure public/private setup with buckets no problem
  2. Buckets are already on a different domain provided by Railway (different from your app).

learn13-tech

interesting to me it seemed like they said that 1. buckets need to be public instead of private 2. buckets need to be on a different domain than the main app

(Buckets are private by default. To download files, you'll need to fetch the file with S3 SDK and stream it through your application, or create a presigned URL for the user to access.)


learn13-tech
FREEOP

6 hours ago

to me it seems lie django says that using a private bucket is not safe enough

No bulletproof technical solution exists at the framework level to safely validate all user uploaded file content, however, there are some other steps you can take to mitigate these attacks:

  1. One class of attacks can be prevented by always serving user uploaded content from a distinct top-level or second-level domain. This prevents any exploit blocked by same-origin policy protections such as cross site scripting. For example, if your site runs on example.com, you would want to serve uploaded content (the MEDIA_URL setting) from something like usercontent-example.com. It’s not sufficient to serve content from a subdomain like usercontent.example.com.

  2. Beyond this, applications may choose to define a list of allowable file extensions for user uploaded files and configure the web server to only serve such files.


learn13-tech
FREEOP

6 hours ago

so basically my bucket must be on a different domain when displaying user content. can railways private buckets allow me to do that ?

since to me it seems like the answer is no


learn13-tech

so basically my bucket must be on a different domain when displaying user content. can railways private buckets allow me to do that ? since to me it seems like the answer is no

Buckets are already on a different domain from your app


learn13-tech

so basically my bucket must be on a different domain when displaying user content. can railways private buckets allow me to do that ? since to me it seems like the answer is no

You'll either stream the file through your web application or get a presigned URL for your user to access.


You don't need a custom domain for that.


0x5b62656e5d

You'll either stream the file through your web application or get a presigned URL for your user to access.

learn13-tech
FREEOP

6 hours ago

that would be safe only if the URL is different from my app's URL, but in this case its not, since my app is using railways domain


The domain presigned URLs are on is t3.storageapi.dev.

I'm not too sure what you're being concerned about here...


learn13-tech
FREEOP

6 hours ago

oh it seems like railways gives you a different domain for buckets ?


learn13-tech
FREEOP

6 hours ago

ye I just saw that


0x5b62656e5d

The domain presigned URLs are on is `t3.storageapi.dev`. I'm not too sure what you're being concerned about here...

learn13-tech
FREEOP

6 hours ago

so railway uses different domains for apps and buckets ?

buckets get : t3.storageapi.dev

and apps get: myapp.up.railway.app

which is 2 different domains, and that would follow the recommendation from the docs

"For example, if your site runs on example.com, you would want to serve uploaded content (the MEDIA_URL setting) from something like usercontent-example.com. It’s not sufficient to serve content from a subdomain like usercontent.example.com."


Yes.


learn13-tech

so railway uses different domains for apps and buckets ? buckets get : t3.storageapi.dev and apps get: myapp.up.railway.app which is 2 different domains, and that would follow the recommendation from the docs "For example, if your site runs on example.com, you would want to serve uploaded content (the MEDIA_URL setting) from something like usercontent-example.com. It’s not sufficient to serve content from a subdomain like usercontent.example.com."

learn13-tech
FREEOP

5 hours ago

I edited it a little bit but im assuming that the answer is still yes, thanks for the help this cleared out a lot

this part of the docs confused me a little bit but idk why

Railway Buckets use virtual-hosted–style URLs, where the bucket name appears as the subdomain of the S3 endpoint. This is the standard S3 URL format, and most libraries support it out of the box. In most cases you only need to provide the base endpoint (https://storage.railway.app) and the client builds the full virtual-hosted URL automatically.

now I know that they use t3.storageapi.dev for serving the content which is a different domain


learn13-tech
FREEOP

5 hours ago

maybe this should be added into the docs ? since I dont see any mention of t3.storageapi.dev


I'm not sure why that information is significant and would affect most users.


learn13-tech
FREEOP

5 hours ago

idk it stopped me dead in my tracks, and its reasonable to check for xss exploits on your website, but most people would not care ab this too

anyway s thanks for the help


Welcome!

Sign in to your Railway account to join the conversation.

Loading...