java如何在flutter中保护restful api端点
我有一个Flatter移动应用程序,可以调用后端API服务器。这需要一个API密钥。我不想将密钥嵌入应用程序。如何保护API密钥和端点以防未经授权的访问。我的应用不需要用户登录
我唯一能想到的想法是有一个pass-thru(nodejs)服务器来调用API服务器,我可以将密钥存储在该服务器上,这样它就不会出现在应用程序中
但是,现在我需要保护节点服务器
有没有关于如何做到这一点的建议,或者你有没有更好的解决方案
谢谢你的建议
范例
class UserService {
Future<List<users>> getUser() async {
var response =
await http.get(Uri.parse(user));
final int statusCode = response.statusCode;
User uData = json.decode(response.body);
return uData
}
}
应用程序。js
var express = require('express');
var app = express();
var PORT = process.env.PORT || 3000;
app.get('/user', function(req, res) {
res.json({
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
})
});
app.listen(PORT);
# 1 楼答案
问题
您已经将问题从保护API后端转移到必须保护直通服务器,正如我在本文中描述的那样,它实际上是一个反向代理Using a Reverse Proxy to Protect Third Party APIs:
逆向工程
因此,事实上,通过使用直通服务器,你可以隐藏你的API密钥,使其不会直接暴露在窥探者的眼睛中,但任何人仍然可以通过直通服务器访问你的后端API,即使你还通过访问密钥(API密钥、令牌等)保护对它的访问,因为他们将通过逆向工程技术或MitM攻击提取访问密钥,就像我在一些文章中描述的:
Steal that Api Key with a Man in the Middle Attack
How to Extract an API key from a Mobile App with Static Binary Analysis
我真的建议任何人阅读上述文章,熟悉从移动应用程序中提取秘密的一些可能方法,因为你将学习几种隐藏这些秘密的方法及其利弊
可能的解决方案
因此,任何在客户端运行并需要一些秘密才能访问API的东西都可能以不同的方式被滥用,您可以从this series篇关于移动API安全技术的文章中了解更多信息。本文将向您介绍如何使用API密钥、用户访问令牌、HMAC和TLS固定来保护API,以及如何绕过它们
要解决什么是访问你的移动应用的问题,你需要使用关于移动API安全技术的系列文章中提到的一个或所有解决方案,我在上面提到了这些解决方案,并承认它们只会使未经授权访问你的API服务器变得更难绕过,但并非不可能
一个可能更好的解决方案
通过使用移动应用认证解决方案,可以使用更好的解决方案,该解决方案将使API服务器知道仅接收来自正版移动应用的请求,并了解更多信息。我建议您阅读我提出的问题this answer如何确保移动应用的API REST,尤其是增强和屏蔽移动应用程序,保护API服务器和可能更好的解决方案部分
你想多跑一英里吗
在回答任何一个安全问题时,我总是喜欢引用OWASP基金会的优秀作品。对于API
OWASP API Security Top 10
对于移动应用
OWASP Mobile Security Project - Top 10 risks
OWASP - Mobile Security Testing Guide