Access control, uploads and (maybe) setting a bad example. #36
-
Questions
ContextI was working with uploads and I couldn't figure out why when I was logged out - my media directory wasn't allowing me to see the static assets I uploaded. I eventually figured out that it was that I need to allow for read permissions on the collection. Something that I couldn't see noted explicitly in the documentation. (Improvement maybe?) As I was doing that I noticed an example I copied from the documentation earlier on my main "Pages" collection (kind of a page builder setup) and it seems to imply public access to creating pages, see bellow. I don't have time to check right now but if it always returns If doesn't use the default checking method, could that maybe be exposed so I don't have to write it myself and import it on every project where I don't need fine-grain access control?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hey @richardvanbergen — great questions! Here are a few answers for you. TL;DR:
Now, here's a bit more info. For safety and security reasons, all access control is set to require that a user is logged in by default to do anything with your API. You need to manually set access control to public for everything, including upload data AND uploaded files, to even be readable by anonymous users. This documentation could be much more bold, or perhaps feature a In many cases, setting
But in any case, public
Nailed it. We'll add this to the docs for sure. Good call.
If the function returns
The default access control method is quite simple, and is below: const defaultAccess = ({ req: { user } }) => Boolean(user); We'll definitely add this to the docs for clarity but there should be no real reason you need to use it - as it's set automatically and used. To make use of it, all you need to do is not set any specific access control property! Does this clear things up for you? All GREAT questions. We appreciate it! |
Beta Was this translation helpful? Give feedback.
-
Hey Richard, no worries! I wrote that up pretty quickly. At this point our team is so familiar with this code that it just flows. We'll keep working on improving our docs and your questions help us do that. Your example will only set the access control for the It's a GOOD thing to be paranoid about access control. That's a mark of a good developer. |
Beta Was this translation helpful? Give feedback.
-
Agree but I think the docs still need an update. I might be interpreting them wrong but the Access Control section states
I intemperate this to mean that read is true and all other operations require auth but currently in my tests, you have the explicitly put
on your collection to get this behaviour. I'm not advocating for a behaviour change, just checking that the documented behaviour and actual behaviour are the same. Perhaps
|
Beta Was this translation helpful? Give feedback.
Hey @richardvanbergen — great questions! Here are a few answers for you.
TL;DR:
access.create: () => true
allows public creation of documents in the collection. We can add to our docs to make this more explicit as it should definitely be used only very deliberately.Now, here's a bit more info.
For safety and security reasons, all access control is set to require that a user is logged in by default t…