You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/02/05 06:36:36 UTC

[GitHub] [apisix] nanamikon opened a new issue #3528: request help: Why ip-restriction return json instead of default 403 error page

nanamikon opened a new issue #3528:
URL: https://github.com/apache/apisix/issues/3528


   ### Issue description
   ip-restriction will return json when the remote ip matches blacklist
   ```
   {"message":"Your IP address is not allowed"}
   ```
   
   I think default 403 error page will be better,  or supporting an option to change this behavior is ok
   
   ### Environment
   
   * apisix version (cmd: `apisix version`): 2.2
   * OS (cmd: `uname -a`): ubuntu
   * OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): 1.19
   * etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):   3.4.13
   * apisix-dashboard version, if have:
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-773884710


   Thanks for reply,   I get your point.    Mixing api with the backstage management  is common usage of gateway in my comany, so I have to provide an option of using 403 error page or  json (as user format)
   
   I can't achieve it without changing code, refer to ip-restriction.lua.
   ```
       if block then
           return 403, { message = "Your IP address is not allowed" }
       end
   ```
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon edited a comment on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon edited a comment on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-774942415


   Refer to apisix/core/response.lua,   resp_exit will be called when response exits,  I think it is a global handle for response exiting, we can't use plugin extension here。  What about redirecting to a new uri to do the actual work ?
   
   Add method 
   ```
   function _M.register_exit_handle_uri(uri){
          handle_uri = uri
   }
   ```
   
   Modify apisix/core/response.lua
   Add exec to redirect to error handle
   ```
       if handle_uri then
           ngx.exec(handle_uri, {code=xxx, body=yyy});
       else
           if idx > 0 then
             ngx_print(concat_tab(t, "", 1, idx))
           end
       
           if code then
               return ngx_exit(code)
           end   
       end
   
   ```
   
   
   Add new config to change this behavior
   ```
   apisix:
         exit_handle_uri:"/error_handle"
        
   ```
   
   New uri for error handle,added by http_server_configuration_snippet 
   ```
       location = /error_handle {
         content_by_lua '
           local args = ngx.req.get_uri_args()
           ngx.print(args.body)
           return ngx.exit(args.code)
         ';
       }
   ```
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] Firstsawyou commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-773839088


   I think it is reasonable to return json. As a gateway, apisix does not need to care about these web pages, this is not what it should focus on. You can display related pages based on the response code returned.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-773884710


   Thanks for reply,   I get your point.    Mixing api with the backstage management  is common usage of gateway in my comany, so I have to provide an option of using 403 error page or  json (as user format)
   
   I can't achieve it without changing code, refer to ip-restriction.lua.
   ```
       if block then
           return 403, { message = "Your IP address is not allowed" }
       end
   ```
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] Firstsawyou commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
Firstsawyou commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-773839088


   I think it is reasonable to return json. As a gateway, apisix does not need to care about these web pages, this is not what it should focus on. You can display related pages based on the response code returned.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon closed issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon closed issue #3528:
URL: https://github.com/apache/apisix/issues/3528


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-773836896


   As an API gateway, we prefer to communicate via HTTP+JSON instead of plain HTML.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-774961528


   Btw,  some issus about how to customize error response format as follow
   
   1 Kong error response
   https://github.com/Kong/kong/issues/3192
   
   2 Upstream error response
   https://github.com/Kong/kong/issues/972
   
   I can't find an official solution in kong so far,and I think it is important to customize apisix error response without modifying code in prd env ,as apsix growing so fast
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-773905814


   You can submit a PR to customize the returned body part.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-774942415


   Refer to apisix/core/response.lua,   resp_exit will be called when error occours,  I think it is a global handle for response exit, we can't use plugin extension here。  What about redirecting to a new uri to do the actual work ?
   
   Add method 
   ```
   function _M.register_exit_handle_uri(uri){
          handle_uri = uri
   }
   ```
   
   Modify apisix/core/response.lua
   Add exec to redirect to error handle
   ```
       if handle_uri then
           ngx.exec(handle_uri, {code=xxx, body=yyy});
       else
           if idx > 0 then
             ngx_print(concat_tab(t, "", 1, idx))
           end
       
           if code then
               return ngx_exit(code)
           end   
       end
   
   ```
   
   
   Add new config to change this behavior
   ```
   apisix:
         exit_handle_uri:"/error_handle"
        
   ```
   
   New uri for error handle,added by http_server_configuration_snippet 
   ```
       location = /error_handle {
         content_by_lua '
           local args = ngx.req.get_uri_args()
           ngx.print(args.body)
           return ngx.exit(args.code)
         ';
       }
   ```
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-773836896






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-775033898


   I think we should open another issue to discuss "exit_handle_uri", as it is not a trivial feature and not only relative with ip-restriction.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon edited a comment on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon edited a comment on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-774942415


   Refer to apisix/core/response.lua,   resp_exit will be called when response exit,  I think it is a global handle for response exit, we can't use plugin extension here。  What about redirecting to a new uri to do the actual work ?
   
   Add method 
   ```
   function _M.register_exit_handle_uri(uri){
          handle_uri = uri
   }
   ```
   
   Modify apisix/core/response.lua
   Add exec to redirect to error handle
   ```
       if handle_uri then
           ngx.exec(handle_uri, {code=xxx, body=yyy});
       else
           if idx > 0 then
             ngx_print(concat_tab(t, "", 1, idx))
           end
       
           if code then
               return ngx_exit(code)
           end   
       end
   
   ```
   
   
   Add new config to change this behavior
   ```
   apisix:
         exit_handle_uri:"/error_handle"
        
   ```
   
   New uri for error handle,added by http_server_configuration_snippet 
   ```
       location = /error_handle {
         content_by_lua '
           local args = ngx.req.get_uri_args()
           ngx.print(args.body)
           return ngx.exit(args.code)
         ';
       }
   ```
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nanamikon commented on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

Posted by GitBox <gi...@apache.org>.
nanamikon commented on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-775637103


   ok


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org