balderdashy / balderdashy/sails

Cannot use function in sails.config.http.trustProxy

Open
#4,444 5 comments 2 reactions 0 assignees View on GitHub
does this answer your question? needs better error message
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Sails version**: 1.0.0
**Node version**: 8.11.2
**NPM version**: 6.0.1 (yarn 1.6.0)
**DB adapter name**: N/A
**DB adapter version**: N/A
**Operating system**: Ubuntu 16.04


I want to whitelist some IP range that can access my app and my app is behind a load balancer.

In this documentation https://sailsjs.com/documentation/reference/configuration/sails-config-http, `sails.config.http.trustProxy` can be either `boolean` or `function`, but when I assign a function, it throws error:

`config/http.js`
```
module.exports.http = {

trustProxy: (ip) => {
// do something here

return true;
}

...
}
```

Error:

```
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
The `sails.config.http.trustProxy` property cannot be zero, empty string, null or NaN.
The property is currently set to: `[Function: trustProxy]`.
To indicate that your app is directly facing the internet, set `trustProxy` to `false`.
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
```

On the documentation, it also refers to express' `trust proxy` https://expressjs.com/en/guide/behind-proxies.html but when I tried to assign comma separated string of IP addresses, it throws similar error.

Do I miss something to configure?

Contributor guide

Open the contributing guide

Research direction

Start with config/http.js and reproduce the issue using the function and comma-separated IP examples from the report. Read the linked Sails HTTP configuration and Express trust proxy documentation, then trace where trustProxy is validated. Done means the documented configuration forms are accepted or the documentation clearly matches the supported behavior, with regression coverage if an existing test entry point is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.