首页 > 其他分享 >通过openresty 解决遗留 webservice 接口安全问题

通过openresty 解决遗留 webservice 接口安全问题

时间:2022-10-07 12:01:35浏览次数:88  
标签:http webservice nginx header token proxy openresty com 遗留

技术一直在变革,老的技术一般都会成为现在的技术债,加上早期大家一般对于安全不是很重视(尤其是在内网环境的时候),尽管webservice 是包含了
ws-security 安全指南的,但是很多时候大家不是很重视(而且这个规范稍晚),以下是一个简单的实践

参考图

通过openresty 解决遗留 webservice 接口安全问题_html

 

 

原理简单说明

核心还是利用了openresty 的阶段处理能力,为了减少业务改造的成本我们可以直接使用影响小的基于header 以及基于ip 防护的处理策略

简单实践

  • 环境准备
    docker-compose.yaml

 


version: '3'
services:
app:
image: openresty/openresty:1.21.4.1-3-alpine-fat
volumes:
- "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
ports:
- "80:80"
nginx.conf 配置

user root;
worker_processes 1;
events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'$http_token';
include mime.types;
default_type application/octet-stream;
gzip on;
rewrite_log on;
real_ip_header X-Forwarded-For;
server {
listen 80;
charset utf-8;
default_type text/html;
location / {
access_by_lua_block {
-- 请求必须携带token,包括wsdl 文件,以及后续操作,实际可以集合认证机制
if ngx.req.get_headers()["token"] == nil then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
}
access_log logs/access2.log main;
sub_filter http://www.dneonline.com 'http://localhost';
sub_filter_types text/xml;
sub_filter_once off;
proxy_set_header Accept-Encoding '';
# 注意使用一个开放的webservice www.dneonline.com
proxy_set_header Host www.dneonline.com;
proxy_set_header X-Forwarded-For $remote_addr;
client_body_buffer_size 10M;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_pass http://www.dneonline.com;
}
}
}
  • api 调用使用了nodejs 的soap 包
var soap = require('soap');
var url = 'http://localhost/calculator.asmx?wsdl';
var args = {intA: 2,intB:3};
soap.createClient(url, {
wsdl_options:{
headers: {'token': 'mytoken'}, // wsdl 携带token
}
}, function(err, client) {
console.dir(client)
client.addHttpHeader("token","mytoken") // 请求携带token
client.Add(args, function(err, result) {
console.log(result.AddResult);
});
});
  • 效果

直接访问(因为没有token 会被拦截)

通过openresty 解决遗留 webservice 接口安全问题_nginx_02

 

 

nginx 请求日志,包含了一个get 以及一个post 请求

通过openresty 解决遗留 webservice 接口安全问题_nginx_03

 

 

node 应用效果

通过openresty 解决遗留 webservice 接口安全问题_html_04

 

 

说明

以上是一个简单的集成,同时包含了如何使用nginx 进行webservice 的代理(核心是sub_filter 指令),对于webservice 的安全实际上问题还是不少的,可以参考
基于ip也是一种模式,header 各种语言的基本都是可以支持的,难度不大

参考资料

​https://www.npmjs.com/package/soap​​​
​​​https://cxf.apache.org/docs/interceptors.html​​​
​​​https://github.com/rongfengliang/openresty-webservice-auth/tree/master​

标签:http,webservice,nginx,header,token,proxy,openresty,com,遗留
From: https://blog.51cto.com/rongfengliang/5734385

相关文章

  • nginx ngx_http_addition_module 模块openresty content_by_lua 不能生效的原因
    nginx的ngx_http_addition_module模块也是一个修改content的好东西,对于openresty我们经常使用content_by_lua阶段处理但是经过分析ngx_http_addition_module源码的......
  • WebService笔记
    【WebService】是一种无关语言无关平台的远程调用技术。WebService是通讯是有状态的,使用Soap简单对象访问协议通讯。 WebService 有三要素:soap、wsdl、udd......
  • loadrunner写webservice接口
    先用soupUI调试 fiddler抓包然后再写:web_custom_request("createSoapOrder",      "URL=http://{hosts}:****/****/webService/eifWebService",     ......
  • podman+openresty+openssl,https双向认证demo测试
    前言暂不讨论https原理,单论配置的话:1.https单项认证server:server.crt+server.keyclient:server_ca.crt2.https双向认证server:server.crt+server.key......
  • OpenResty+Lua限流实战--resty.limit.conn(用于限制并发连接数)
    限制并发场景1:按照ip限制其并发连接数原理:lua_share_dict是nginx所有woker和luaruntime共享的,当一个请求进来,往lua_share_dict记录键值对ip地址:1,当请求完成时再-1,再......
  • [nginx]编译安装openresty
    前言OpenResty是一个基于Nginx和Lua的高性能Web平台,其内部集成了大量精良的Lua库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态We......
  • .NET代码审计之WebService安全
    背景是微信群里有伙伴问起asmx接口怎么测试,其实和其他语言的API接口一样,每一条接口都有可能存在SQL注入、XXE、文件读取写入等风险,代码审计时需关注扩展名为.asmx的文件。......
  • 使用axis2生成webService客户端代码并使用(做个记录)
    背景:公司以前用过一次axis2,调用webservice,但是因为过去大半年的时间当再一次有需求使用axis2的时候发现自己忘得差不多了,这里做一个记录.1)首先根据wsdl生成客户端代......
  • C# Webservice 上传文件保存 413 (Request Entity Too Large)
    文件太大,需要调整配置文件在webconfig下插入以下代码:<system.webServer><security><requestFiltering><requestLimitsmaxAllowedContentLength=......
  • 《遗留系统现代化实战》读书笔记
    遗留系统的定义请你先思考这样一个问题:假如一个系统七八年了,它是不是个遗留系统?系统的时间长等同于就是遗留系统,这是很多人的一个误区。虽然大多数遗留系统确实是存在的时......