Skip to content

Commit

Permalink
Added a section on security (#3408)
Browse files Browse the repository at this point in the history
* security

* added section on security

* security

* changes from review
  • Loading branch information
abidlabs authored Mar 7, 2023
1 parent a5e3be7 commit 2fd9b55
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ No changes to highlight.
- Prevent in-place updates of `generic_update` by shallow copying by [@gitgithan](https://github.com/gitgithan) in [PR 3405](https://github.com/gradio-app/gradio/pull/3405) to fix [#3282](https://github.com/gradio-app/gradio/issues/3282)

## Documentation Changes:

- Added a section on security and access when sharing Gradio apps by [@abidlabs](https://github.com/abidlabs) in [PR 3408](https://github.com/gradio-app/gradio/pull/3408)
- Add Chinese README by [@uanu2002](https://github.com/uanu2002) in [PR 3394](https://github.com/gradio-app/gradio/pull/3394)

## Testing and Infrastructure Changes:
Expand Down
2 changes: 2 additions & 0 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,8 @@ def reverse(text):
self.show_api = self.api_open if self.enable_queue else show_api

self.file_directories = file_directories if file_directories is not None else []
if not isinstance(self.file_directories, list):
raise ValueError("file_directories must be a list of directories.")

if not self.enable_queue and self.progress_tracking:
raise ValueError("Progress tracking requires queuing to be enabled.")
Expand Down
17 changes: 17 additions & 0 deletions guides/01_getting-started/03_sharing-your-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ How to share your Gradio app:
6. [Adding authentication to the page](#authentication)
7. [Accessing Network Requests](#accessing-the-network-request-directly)
8. [Mounting within FastAPI](#mounting-within-another-fastapi-app)
9. [Security](#security-and-file-access)

## Sharing Demos

Expand Down Expand Up @@ -105,6 +106,8 @@ btn.click(add, [num1, num2], output, api_name="addition")

This will document the endpoint `/api/addition/` to the automatically generated API page.

*Note*: For Gradio apps in which [queueing is enabled](https://gradio.app/key-features#queuing), users can bypass the queue if they make a POST request to your API endpoint. To disable this behavior, set `api_open=False` in the `queue()` method.

## Authentication

You may wish to put an authentication page in front of your app to limit who can open your app. With the `auth=` keyword argument in the `launch()` method, you can provide a tuple with a username and password, or a list of acceptable username/password tuples; Here's an example that provides password-based authentication for a single user named "admin":
Expand Down Expand Up @@ -157,3 +160,17 @@ Here's a complete example:
$code_custom_path

Note that this approach also allows you run your Gradio apps on custom paths (`http://localhost:8000/gradio` in the example above).

## Security and File Access

Sharing your Gradio app with others (by hosting it on Spaces, on your own server, or through temporary share links) **exposes** certain files on the host machine to users of your Gradio app. This is done so that Gradio apps are able to display output files created by Gradio or created by your prediction function.

In particular, Gradio apps grant users access to three kinds of files:

* Files in the same folder (or a subdirectory) of where the Gradio script is launched from. For example, if the path to your gradio scripts is `/home/usr/scripts/project/app.py` and you launch it from `/home/usr/scripts/project/`, then users of your shared Gradio app will be able to access any files inside `/home/usr/scripts/project/`. This is needed so that you can easily reference these files in your Gradio app.

* Temporary files created by Gradio. These are files that are created by Gradio as part of running your prediction function. For example, if your prediction function returns a video file, then Gradio will save that video to a temporary file and then send the path to the temporary file to the front end.

* Files that you explicitly allow via the `file_directories` parameter in `launch()`. In some cases, you may want to reference other files in your file system. The `file_directories` parameter allows you to pass in a list of additional directories you'd like to provide access to. (By default, there are no additional file directories).

Users should NOT be able to access other arbitrary paths on the host.

0 comments on commit 2fd9b55

Please sign in to comment.