Security ';cat数据| curl-d@-http://host:8080/webapp`:我可以通过管道将流导入servlet吗?
我编写了以下servlet,它将输入转换为大写:Security ';cat数据| curl-d@-http://host:8080/webapp`:我可以通过管道将流导入servlet吗?,security,servlets,stream,Security,Servlets,Stream,我编写了以下servlet,它将输入转换为大写: public class TestServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { InputStream in=req.getInputS
public class TestServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
InputStream in=req.getInputStream();
OutputStream out=resp.getOutputStream();
byte array[]=new byte[1024];
int nReads;
while((nReads=in.read(array))!=-1)
{
for(int i=0;i<nReads;++i)
{
array[i]=(byte)Character.toUpperCase(array[i]);
}
out.write(array, 0, nReads);
}
out.flush();
out.close();
}
}
部署这样的servlet安全吗?这种servlet的陷阱是什么?例如,如何防止用户永远阻止我的servlet实例:
cat | curl -d @- "http://localhost:8080/app/test/x"
不,您不能通过管道将流传输到servlet。HTTP并没有真正提供输入流
您的命令之所以有效,是因为cat
输出数据后返回curl
然后获取所有数据并发送。但是,curl
在获取数据之前不会发送任何内容
当然,这样做的好处是不会阻塞servlet的实例,因为阻塞发生在curl,而不是servlet
cat | curl -d @- "http://localhost:8080/app/test/x"