Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[THREESCALE-2775] [Policy] IP Check uses multiple x-forwarder-for headers. #1065

Merged
merged 1 commit into from
Jun 11, 2019

Conversation

eloycoto
Copy link
Contributor

This change allows to block traffic when multiple x-forwarder-for are defined
in the same request. Resty creates an array with all duplicated headers, so in
case of a array only the first heaeder will be used.

Also, adds the integration test to make sure that no regression in this case.

Example request to make it fail:

curl localhost:8080?user_key=123
    -H "X-Forwarded-For: 1.2.3.4" \
    -H "Host:one" \
    -H "X-Forwarded-For: 1.2.3.44"  \
    -v

config:

{
  "services": [
    {
      "id": 200,
      "endpoint": "http://localhost:8080",
      "backend_version": "1",
      "proxy": {
        "service_backend_version": "1",
        "hosts": [
                  "one"
              ],
        "api_backend": "https://echo-api.3scale.net:443",
        "proxy_rules": [
          { "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 1 }
        ],
        "policy_chain": [
          { "name": "apicast.policy.apicast" },
          {
            "name": "ip_check",
            "version": "builtin",
            "configuration": {
              "error_msg": "IP address not allowed",
              "client_ip_sources": [
                "X-Forwarded-For"
              ],
              "ips": [
                "1.2.3.4"
              ],
              "check_type": "blacklist"
            }
          }
        ]
      }
    }
  ]
}

Fixes #1061

Signed-off-by: Eloy Coto eloy.coto@gmail.com

--- no_error_log
[error]

=== TEST 10: Validate that X-Forwarded-Host header is working
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be X-Forwarded-For instead of Host.

@davidor
Copy link
Contributor

davidor commented Jun 11, 2019

Added a minor comment.

Looks good 👍

This change allows to block traffic when multiple x-forwarder-for are defined
in the same request. Resty creates an array with all duplicated headers, so in
case of a array only the first heaeder will be used.

Also, adds the integration test to make sure that no regression in this case.

Example request to make it fail:

```
curl localhost:8080?user_key=123
    -H "X-Forwarded-For: 1.2.3.4" \
    -H "Host:one" \
    -H "X-Forwarded-For: 1.2.3.44"  \
    -v
```

config:
```
{
  "services": [
    {
      "id": 200,
      "endpoint": "http://localhost:8080",
      "backend_version": "1",
      "proxy": {
        "service_backend_version": "1",
        "hosts": [
                  "one"
              ],
        "api_backend": "https://echo-api.3scale.net:443",
        "proxy_rules": [
          { "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 1 }
        ],
        "policy_chain": [
          { "name": "apicast.policy.apicast" },
          {
            "name": "ip_check",
            "version": "builtin",
            "configuration": {
              "error_msg": "IP address not allowed",
              "client_ip_sources": [
                "X-Forwarded-For"
              ],
              "ips": [
                "1.2.3.4"
              ],
              "check_type": "blacklist"
            }
          }
        ]
      }
    }
  ]
}
```

Fixes 3scale#1061

Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
@eloycoto eloycoto requested a review from davidor June 11, 2019 13:22
@davidor davidor changed the title [Policy] IP Check uses multiple x-forwarder-for headers. [THREESCALE-2775] [Policy] IP Check uses multiple x-forwarder-for headers. Jun 11, 2019
@davidor davidor merged commit d447f52 into 3scale:master Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IP Check Policy doesn't work on OpenShift
2 participants