Form Specific Data Table Access

Currently I’m building a CSV Data Tables UI driven utility. This will allow upserting from CSV, inserting from CSV, formatting validation, etc… Which will be free to use once complete :slight_smile:

fun

Currently, access for forms is all or nothing, with no way to specify particular forms with particular permissions:
fun

What I’m proposing is that in this area of the data table, we get access to specifying particular forms with particular permissions.

In my case, it’s because I want to utilize my CSV data table management tool to be able to manipulate data in any table.

I know I can’t have been the only one to build management tools for anvil, only to have to stuff them in another app.

1 Like

I don’t see any particular purpose for it. Because a determined person can easily access whatever form they want. So it offers you no security.

I’m not familiar with the internal workings of the Anvil security model really so I wouldn’t know.

I assumed that this statement from the docs " Anvil intends to provide an intuitive security model. The basic principle is, “If you can see it, you can use it” . This is more formally known as a capability system ." Means that if you expose visually to the user, then they can access it.

What I’m proposing would basically be don’t have any links or UI that references the management UI, and could only be run by devs by changing the app startup form to run it, or to login to the app as a developer which gives you special access.

So any user of the app can access any form? Seems like a big security flaw.
If so, I’d need to rethink this, because I’d only want devs of the app to have access to it.

Do you have a suggestion on how to achieve this?

My apps for devs have access to dev stuff, my apps for less cool users have access only to stuff for less cool uers.

In order for a form to have access to a table, the browser needs access to a table, and when the browser has access to a table, any hacker has access to that table, without even passing through the form.

If you want to make something polished, then your form should use server calls to access the table, not use direct access.

If you want to do something quick, then your form should only be used by admin with full access apps.

3 Likes

It isn’t really a flaw. It’s just how the client-side is. You might want to consider checking this Bypass user login - #2 by rickhurlbatt

@rickhurlbatt makes a wonderful point here


Also, I have demonstrated Server-Side routing here which relies on server to return forms. You can try to build something like that. Although unless you want the additional benefits that it provides, I will suggest sticking to the above advice

I would say this is definitely the route to go.

If you want role management, extras has a simple library for you to implement and play with, so you don’t have to develop your own. :slight_smile:

This way you can control what a user can do by protecting your server functions.

https://anvil-extras.readthedocs.io/en/latest/guides/modules/authorisation.html

EDIT: This was meant to “quote Stefano” and reply to the main question :man_facepalming:

3 Likes

So:

" “If you can see it, you can use it”

Does not imply,

“Means that if you only expose visually to the user, then they can access it.”

?

I’m confused about this statement now.

Maybe there should be a “Developer Only” form feature. Where standard users don’t have access to creating it, and only developers can create and use it for management purposes of the app.

This is not the case.

The form can do self.container_1.visible = True and show anything. That code can be written on the browser console, the fact that you don’t write it doesn’t mean that it will not work. (you can’t really open the console and write that code, because the console speaks Javascript, not Python, but any decent hacker can do that).

Similarly if the code in the form can do app_tables.my_table.delete_all_rows(), then any hacker can do that.

Thank you for clarifying that.

I guess I don’t understand why anvil would allow data tables access at all from the forms.

It seems like it would only be useful for throwaway apps that don’t require real security, and would entrain bad practices in the minds of developers.

Maybe there should be an option when creating apps. Playground Mode and Professional Mode.

It’s good for rapid prototyping, when you work on a proof of concept, or when you learn.

It’s definitely not good for safe production apps.

As I suggested earlier, I always transfer data via server calls, I never give access to the tables to a form.

When I teach people how to use Anvil I always start from there and I say “I’m going to show you something that is awesome and that you should never do, but it’s good to see that it works, so you understand how Anvil works”. If I’m talking to expert web developers they are surprised by how easy is to access the database and they do understand the safety concerns. If I’m talking to beginners, I show how it works and explain why it’s dangerous.

Yes, perhaps the documentation should mention a little more details here.

1 Like

Man, I think role / user based protections on server functions should be baked into Anvil by default.

Maybe a new service / config option.

I think anvil is taking to stance of creating a completely open tool, starting as basic as possible and giving the user the maximum control. (Speculation more than knowledge)

And the community has developed tools so the anvil team didn’t have too.

But, agreeing with you and @stefano.menci , maybe there should be more warnings in the documentation for the ignorant, as I certainly was when starting.

This forum has been a great source of education though, so I’d hope people would read more before jumping in on a project.

This would be a great feature request :slight_smile:

EDIT:

Here is some documentation!

1 Like

See the feature request :slight_smile:

Allowing forms to write to data tables is generally something you will not prefer (unless you are working with a group of people you completely trust). Although in many cases, it’s totally fine to let them view data tables.

Agreed, there are data tables that are perfectly safe to allow unrestricted reading from the client side. Validation tables, for example, e.g. a list of categories for the user to choose from.

I typically don’t allow reading even for those tables, preferring to use server functions, but I wouldn’t want to lose the ability to mark a table for client reading.

2 Likes

With the Accelerated Tables feature (now in public beta), read-only views have a decided advantage in performance and simplicity of coding. You’ll still want to exclude any sensitive columns from those tables; e.g., move them to their own “shadow” tables.

As others have said, creating a separate app (that shares the relevant Data Tables) seems a good solution to me. What difficulties have you run into with that approach, though, because I haven’t tried it yet myself?

Just to reiterate, the “see” here is not referring to whether something is displayed visually in the UI but rather whether something is accessible to client-side code more generally.

4 Likes

Wait… you can have two apps pointing to the same Data Tables?

How?

https://anvil.works/docs/data-tables#sharing-data-tables-between-apps

I think it may not yet be possible in the Beta IDE, though.

3 Likes