|
26 | 26 | SECRET = os.environ.get("FLASK_SECRET", "secret")
|
27 | 27 | URL_PREFIX = os.environ.get("FLASK_PREFIX", "") # if not empty, this value should begin but not end in a slash ('/')
|
28 | 28 |
|
29 |
| -# REVERSE_PROXIED is a boolean value that indicates whether or not this server instance |
30 |
| -# is running behind a reverse proxy (like nginx). |
31 |
| -# in dev and testing, it is fine (or even preferable) for this variable to be set to 'TRUE' |
32 |
| -# even if it is not actually the case. in prod, it is very important that this is set accurately -- |
33 |
| -# it should _only_ be set to 'TRUE' if it really is behind a reverse proxy, as remote addresses can be "spoofed" |
34 |
| -# which can carry security/identity implications. conversely, if this is set to 'FALSE' when in fact |
35 |
| -# running behind a reverse proxy, it can hinder logging accuracy. it defaults to 'FALSE' for safety. |
36 |
| -REVERSE_PROXIED = os.environ.get("REVERSE_PROXIED", "FALSE").upper() == "TRUE" |
| 29 | + |
| 30 | +""" |
| 31 | +REVERSE_PROXY_DEPTH is an integer value that indicates how many "chained" and trusted reverse proxies (like nginx) this |
| 32 | + server instance is running behind. "chained" refers to proxies forwarding to other proxies, and then ultimately |
| 33 | + forwarding to the app server itself. each of these proxies appends the remote address of the request to the |
| 34 | + "X-Forwarded-For" header. in many situations, the most externally facing proxy (the first in the chain, the one that |
| 35 | + faces the "open internet") can and should be set to write its own "X-Forwarded-For" header, ignoring and replacing |
| 36 | + (or creating anew, if it didnt exist) such a header from the client request -- thus preserving the chain of trusted |
| 37 | + proxies under our control. |
| 38 | +
|
| 39 | +however, in our typical production environment, the most externally facing "proxy" is the AWS application load balancer, |
| 40 | + which seemingly cannot be configured to provide this trust boundary without losing the referring client address |
| 41 | + (see: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html ). accordingly, in |
| 42 | + our current typical production environment, REVERSE_PROXY_DEPTH should be set to "2": one for the AWS application load |
| 43 | + balancer, and one for our own nginx/haproxy instance. thus "2" is our default value. |
| 44 | +
|
| 45 | +it is important that REVERSE_PROXY_DEPTH is set accurately for two reasons... |
| 46 | +
|
| 47 | +setting it too high (or to -1) will respect more of the entries in the "X-Forwarded-For" header than are appropriate. |
| 48 | + this can allow remote addresses to be "spoofed" when a client fakes this header, carrying security/identity |
| 49 | + implications. in dev and testing, it is not particularly dangerous for this variable to be set to -1 (special case |
| 50 | + for an "infinite" depth, where any and all proxy hops will be trusted). |
| 51 | +
|
| 52 | +setting it too low can hinder logging accuracy -- that can cause an intermediate proxy IP address to be used as the |
| 53 | + "real" client IP address. |
| 54 | +
|
| 55 | +setting REVERSE_PROXY_DEPTH to "0" essentially indicates there are no proxies between this server and the outside |
| 56 | + world. in this case, the "X-Forwarded-For" header is ignored. |
| 57 | +""" |
| 58 | +REVERSE_PROXY_DEPTH = int(os.environ.get("PROXY_DEPTH", 2)) |
| 59 | + |
37 | 60 |
|
38 | 61 | REGION_TO_STATE = {
|
39 | 62 | "hhs1": ["VT", "CT", "ME", "MA", "NH", "RI"],
|
|
0 commit comments