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 ?
22 Replies
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
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.
6 hours ago
but my main app is already on railways domain tho
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."
6 hours ago
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.
6 hours ago
interesting to me it seemed like they said that
- buckets need to be public instead of private
- 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
6 hours ago
- You can configure public/private setup with buckets no problem
- 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
6 hours ago
(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.)
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:
-
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.
-
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.
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
6 hours ago
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
6 hours ago
You'll either stream the file through your web application or get a presigned URL for your user to access.
0x5b62656e5d
You'll either stream the file through your web application or get a presigned URL for your user to access.
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
6 hours ago
The domain presigned URLs are on is t3.storageapi.dev.
I'm not too sure what you're being concerned about here...
6 hours ago
oh it seems like railways gives you a different domain for buckets ?
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...
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."
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."
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
5 hours ago
maybe this should be added into the docs ? since I dont see any mention of t3.storageapi.dev
5 hours ago
I'm not sure why that information is significant and would affect most users.
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

