Skip to content

Commit 40c80c4

Browse files
Merge pull request #7011 from hotosm/feat/update-docs
Update docs
2 parents ad2a9f6 + 98fc713 commit 40c80c4

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

docs/sysadmins/cors.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# CORS
2+
3+
With the version 5, we’re taking small, deliberate steps towards OWASP standards and tightening up our CORS policy
4+
was done as one of those “tiny steps”. It’s not meant to be a hurdle for developers but rather a browser‑based
5+
safeguard that helps prevent cross‑site request forgery and other attacks at end user's that could silently exfiltrate
6+
a user’s credentials or data.
7+
8+
**Where the setting lives**
9+
10+
* CORS is controlled by the `EXTRA_CORS_ORIGINS` environment variable in the app config. If it is **not** set, all origins are allowed by default.
11+
* `http://localhost:3000` is already whitelisted on the staging and dev API instances (`https://tasking-manager-staging-api.hotosm.org/api/docs` and `https://tasking-manager-dev-api.hotosm.org/api/docs`) so you can develop locally without CORS errors.
12+
* If a production frontend needs direct browser access, contact the system admin (support) to request the exact origin be added to the whitelist.
13+
14+
* For any browser‑based clients calling the TM API directly are now blocked by the CORS.
15+
For any production frontends running that want direct access to the TM API in-browser,
16+
we can also allow them by adding to our whitelist for which the admins can be contacted
17+
and the origin can be whitelisted. Please feel free to contact the system admin via the support section
18+
if any whitelisting necesssary.
19+
20+
---
21+
22+
## Local development options
23+
24+
### 1) Local nginx reverse-proxy
25+
26+
* **What:** Run a tiny nginx container that forwards requests to the TM API and injects permissive CORS headers for your browser.
27+
* **Advantages:** Easy to run (single container), works for any client, replicates production TLS/host header behaviour, can be shared among a team.
28+
* **Disadvantages / cautions:** Bypasses browser protections — **do not** expose publicly or use in production. If you need credentials (cookies) set explicit `Access-Control-Allow-Origin` and `Access-Control-Allow-Credentials` instead of `*`.
29+
30+
**Minimal nginx.conf (development only)**
31+
32+
```nginx
33+
http {
34+
server { listen 80; location / {
35+
proxy_pass https://tasking-manager-production-api.hotosm.org/;
36+
if ($request_method = OPTIONS) {
37+
add_header 'Access-Control-Allow-Origin' '*' always;
38+
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,PATCH,DELETE,OPTIONS' always;
39+
add_header 'Access-Control-Allow-Headers' 'Content-Type,Authorization' always;
40+
return 204;
41+
}
42+
add_header 'Access-Control-Allow-Origin' '*' always;
43+
}}
44+
}
45+
```
46+
47+
**Run:**
48+
49+
```bash
50+
docker run -d --name cors-proxy -p 8080:80 \
51+
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro \
52+
nginx:alpine
53+
```
54+
55+
Access via `http://localhost:8080`.
56+
57+
### 2) Cloudflare Worker proxy
58+
59+
* See `kshitijrajsharma/tm-cors-proxy` a ready-made Cloudflare Worker proxy implementation that forwards browser requests to the TM API and injects CORS headers.
60+
61+
---

docs/sysadmins/migration.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@ please do always backups and run the migration first in a testing
66
environment, make sure everything works as expected before you move
77
on!
88

9+
## Migration from version 4 to version 5
10+
11+
The version 5 of the Tasking Manager has major stack update.
12+
Tasking Manager version 4 was a synchronous application built with Flask backend
13+
and psycopg2 as database driver which is migrated to FastAPI backend and asyncpg.
14+
15+
16+
To migrate Tasking Manager from version 4 to 5, first and optionally,
17+
you might want take a backup of the database. Although no specific database changes,
18+
but a database backup before a major transition is always a good practice. For
19+
the database backup you can run
20+
21+
$ `pg_dump -h <host> -p <port> -U <user> -d <dbname> -f ./backup.sql`
22+
23+
The latest/development branch is the develop branch.
24+
Use main branch instead of develop for stability
25+
Simply pull/rebase the develop/main branch and build.
26+
27+
$ `docker compose up --build`
28+
29+
Note: ${TARGET_TAG} in docker-compose for different (development/deployment) environment. Use debug
30+
for development purpose and prod for deployment purpose.
31+
32+
Since docker compose has the .env file as default environment file,
33+
the convention of using the non standard dotenv tasking-manager.env
34+
might result in a database health-check warning - postgres user does not exist.
35+
36+
You can specify the file with the command
37+
38+
$ `docker compose --env-file tasking-manager.env up -d`
39+
40+
Also note that if you're using wsgi server, the version 5 might be incompatible
41+
with it. Instead, uvicorn can be used, which is also updated on the Dockerfile
42+
on the scripts/docker/Dockerfile and running through the command
43+
44+
$ `CMD ["uvicorn", "backend.main:api", "--host", "0.0.0.0", "--port", "5000", \
45+
"--workers", "8", "--log-level", "critical","--no-access-log"]`
46+
947
## Migration from version 3 to version 4
1048

1149
First and optionally, you might want to run the following SQL script

0 commit comments

Comments
 (0)