Skip to content

Commit 69b9f6a

Browse files
committed
docs: update readme
Updates README.md with details on configuring the Shopify whitelist
1 parent d535435 commit 69b9f6a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ Set the TPG_JWT_SIGNING_KEY and TPG_JWT_VERIFICATION_KEY environment variables i
3636
🚨️🚨️🚨️
3737
```
3838

39+
## Shopify whitelisting
40+
41+
Orders are submitted to the server via the `/shopify/webhook/*` endpoints. This are called by shopify's webhook system.
42+
However, if anyone could make calls to that endpoint, they could submit fake orders to the server.
43+
One set of protections against this is to whitelist the IP addresses of Shopify's webhook servers.
44+
45+
All endpoints under the `/shopify` scope are checked against the shopify IP whitelist. These are configured via the
46+
`TPG_SHOPIFY_IP_WHITELIST` environment variable. This is a comma-separated list of IP addresses.
47+
For example,
48+
```
49+
TPG_SHOPIFY_IP_WHITELIST=192.168.1.1,192.168.1.5,10.0.0.2
50+
```
51+
52+
When an incoming request is made, the server will check the IP address of the request against the whitelist. The IP is taken
53+
from the remote peer of the connection. If the Tari payment server is behind a load balancer, this might cause the check
54+
to fail, since the IP address of the load balancer will be checked, rather than the IP address of the Shopify server.
55+
56+
To work around this, you can set the `TPG_USE_X_FORWARDED_FOR` or `TPG_USE_FORWARDED` environment variables to `1` or `true`.
57+
The server will then use the IP address in the `X-Forwarded-For` or `Forwarded` headers, respectively.
58+
59+
Your proxy or load balancer must then be configured to set these headers and should take precautions against header spoofing.
60+
61+
🚨️🚨️🚨️ **WARNING** 🚨️🚨️🚨️
62+
63+
Attackers can trivially spoof `X-Forwarded-For` or `Forwarded` headers. So be careful if using these options and ensure that
64+
your proxy or load balancer takes precautions to detect spoofing (such as comparing against the remote peer's IP address).
65+
3966
## Server configuration
4067

4168
The server is configured via the following environment variables:

tari_payment_server/src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn create_server_instance(config: ServerConfig, db: SqliteDatabase) -> Resul
8686
.get("X-Forwarded-For")
8787
.and_then(|v| use_x_forwarded_for.then(|| v.to_str().ok()).flatten())
8888
.or_else(|| {
89-
req.headers().get("X-Real-IP").and_then(|v| use_forwarded.then(|| v.to_str().ok()).flatten())
89+
req.headers().get("Forwarded").and_then(|v| use_forwarded.then(|| v.to_str().ok()).flatten())
9090
})
9191
.or_else(|| peer_addr.as_ref().map(|s| s.as_str()))
9292
.and_then(|s| SocketAddr::from_str(s).ok());

0 commit comments

Comments
 (0)