如果仅被Android应用程序消耗,则可以在没有HTTPS和JWT的情况下开发REST API?

发布于 2025-01-18 02:05:46 字数 123 浏览 2 评论 0原文

我计划用 JAVA 和 Spring Boot 创建一个后端应用程序,它有一组 REST API。如果这些 API 由单个 Android 应用程序使用,那么我是否需要使用 HTTPS (SSL/TLS)、JWT 令牌等来保护它们。

I am planning to create an back end application in JAVA and Spring Boot which has a set of REST APIs. If these APIs are consumed by a single Android application then do I need to secure them using HTTPS (SSL/TLS), JWT token etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一曲爱恨情仇 2025-01-25 02:05:46

APIS 中应该使用 HTTPS 吗?

我计划用 JAVA 和 Spring Boot 创建一个后端应用程序,它有一组 REST API。如果这些 API 由单个 Android 应用程序使用,那么我是否需要使用 HTTPS (SSL/TLS)、JWT 令牌等来保护它们的安全。

。绝对是的。

现在没有理由不使用 HTTPS,我在我的文章中讨论了为什么应该使用 HTTPS 六大移动 API 保护技术 - 它们足够了吗?

在本文中,我们将探讨用于保护 API 的最常用技术,包括使用 HTTPS 保护移动应用程序与 API 之间的通信通道的重要性、如何使用 API 密钥来识别每个应用程序上的移动应用程序。 API 请求,如何使用用户代理、验证码和 IP 地址来缓解机器人攻击,以及最后用户身份验证对于移动安全和 API 安全的重要性。我们将讨论这些技术中的每一种,并讨论它们如何影响业务风险状况,即它们是如何容易绕过的。

读者将会明白为什么当今常用的移动 API 保护技术非常幼稚,不适合保护数字企业免受 API 滥用的目的。大多数企业都意识到 API 滥用的形式多种多样,因此采用正确的技术来维持收入和品牌声誉非常重要。

HTTPS 足以保护 API 的安全吗?

不可以,因为存在许多逆向工程技术和工具来绕过 HTTPS 在移动应用程序和 API 服务器之间提供的安全通信通道。

一种非常流行的技术是部署中间人 (MitM) 攻击,这将允许攻击者解密他控制的设备中的 HTTPS 流量或诱导用户安装自定义证书,但这可以通过以下方式来阻止:使用证书固定。

您可以在我的文章 通过中间人攻击窃取 Api 密钥

为了帮助演示如何窃取 API 密钥,我在 Github 上构建并发布了 适用于 Android 的货币转换器演示 应用程序,它使用相同的 JNI/NDK 我们在之前的 Android 隐藏秘密应用程序到 隐藏API 密钥

因此,在本文中,您将了解如何设置和运行 MitM 攻击,以拦截您控制下的移动设备中的 https 流量,以便窃取 API 密钥。最后,您将在较高层面上了解如何缓解 MitM 攻击。

使用证书固定保护 HTTPS

要防止发生 MitM 攻击,您可以在移动应用程序上部署证书固定,您可以在我的文章中了解更多信息 使用证书固定保护 HTTPS

为了演示如何使用证书固定来保护移动应用程序和 API 服务器之间的 https 流量,我们将使用相同的 货币转换器演示我在上一篇文章中使用的移动应用程序。

在本文中,我们将了解什么是证书固定、何时使用它、如何在 Android 应用中实现它,以及它如何防止 MitM 攻击。

本文将向您展示如何使用移动证书固定生成器,这是一个在线免费工具,可以让您准备好使用 Android 和 iOS 的配置文件并配置固定。

只需添加要固定的 API 域:

Config tab

然后将配置复制并粘贴到您的 Android 应用程序中:

Android tab

请阅读工具常见问题解答,了解使用静态证书固定的利弊和陷阱 选项卡

证书固定涉及将预期的 pin 静态嵌入到应用程序本身中。更改引脚需要发布应用程序更新。

DevOps 团队在未与开发人员沟通的情况下轮换服务器证书,或者未能与包含新公钥 pin 的新版本移动应用程序的发布协调轮换。

FAQ tab

您想加倍努力吗?

在回答安全问题时,我总是喜欢参考 OWASP 基金会的出色工作。

对于 APIS

OWASP API 安全性前 10 名

OWASP API 安全项目旨在通过强调不安全 API 中的潜在风险并说明如何减轻这些风险,为软件开发人员和安全评估人员提供价值。为了实现这一目标,OWASP API 安全项目将创建并维护十大 API 安全风险文档,以及创建或评估 API 时最佳实践的文档门户。

对于移动应用

OWASP 移动安全项目 - 十大风险

OWASP 移动安全项目是一个集中资源,旨在为开发人员和安全团队提供构建和维护安全移动应用程序所需的资源。通过该项目,我们的目标是对移动安全风险进行分类并提供开发控制以减少其影响或被利用的可能性。

OWASP - 移动安全测试指南

移动安全测试指南 (MSTG) 是一本针对移动应用安全开发、测试和逆向工程的综合手册。

Should HTTPS be Used in APIS?

I am planning to create an back end application in JAVA and Spring Boot which has a set of REST APIs. If these APIs are consumed by a single Android application then do I need to secure them using HTTPS (SSL/TLS), JWT token etc.

Absolutely Yes.

No reason exists nowadays for not using HTTPS and I talk about why you should use HTTPS in my article The Top 6 Mobile API Protection Techniques - Are They Enough?:

In this article we will explore the most common techniques used to protect an API, including how important it is to use HTTPS to protect the communication channel between mobile app and API, how API keys are used to identify the mobile app on each API request, how user agents, captchas and IP addresses are used for bot mitigation, and finally how user authentication is important for the mobile security and api security. We will discuss each of these techniques and discuss how they impact the business risk profile, i.e. how easy they are get around.

The reader will come to understand why today’s commonly used mobile API protection techniques are very naive and not fit for purpose to defend digital businesses against API abuse. API abuse is its various forms is much more commonplace that most businesses realize so it is important to employ the right techniques to maintain revenue and brand reputation.

Is HTTPS enough to secure the API?

No, because a lot of reverse engineer techniques and tools exist to byapss the secure communication channel that HTTPS provides between the mobile app and the API server.

A very popular technique is to deploy a Man in the Middle (MitM) attack, that will allow for an attacker to decrypt the HTTPS traffic in a device he controls or have induced the user to install custom certificates, but this can be prevented with the use of certificate pinning.

You can learn more about how a MitM attack is carried out in my article Steal that Api Key with a Man in the Middle Attack:

In order to help to demonstrate how to steal an API key, I have built and released in Github the Currency Converter Demo app for Android, which uses the same JNI/NDK technique we used in the earlier Android Hide Secrets app to hide the API key.

So, in this article you will learn how to setup and run a MitM attack to intercept https traffic in a mobile device under your control, so that you can steal the API key. Finally, you will see at a high level how MitM attacks can be mitigated.

Securing HTTPS with Certificate Pinning

To prevent MitM attacks to occur you can deploy certificate pinning on your mobile app, and you can learn more about in my article Securing HTTPS with Certificate Pinning:

In order to demonstrate how to use certificate pinning for protecting the https traffic between your mobile app and your API server, we will use the same Currency Converter Demo mobile app that I used in the previous article.

In this article we will learn what certificate pinning is, when to use it, how to implement it in an Android app, and how it can prevent a MitM attack.

This article will show you how to use the Mobile Certificate Pinning Generator, an online free tool that will give you ready to use configuration files for Android and iOS with pinning configured.

Simply add the API domain to pin against:

Config tab

And then copy and paste the configuration into your Android app:

Android tab

Please be aware of the trade-offs and pitfalls of using static certificate pinning by reading the tool faq tab:

Certificate pinning involves statically embedding the expected pins into the app itself. Changing the pins requires an update of the app to be issued.

The DevOps team rotates the server certificate without communicating it to the developers or fails to coordinate the rotation with the release of a new version of the mobile app containing a new public key pin.

FAQ tab

Do You Want To Go The Extra Mile?

In any response to a security question I always like to reference the excellent work from the OWASP foundation.

For APIS

OWASP API Security Top 10

The OWASP API Security Project seeks to provide value to software developers and security assessors by underscoring the potential risks in insecure APIs, and illustrating how these risks may be mitigated. In order to facilitate this goal, the OWASP API Security Project will create and maintain a Top 10 API Security Risks document, as well as a documentation portal for best practices when creating or assessing APIs.

For Mobile Apps

OWASP Mobile Security Project - Top 10 risks

The OWASP Mobile Security Project is a centralized resource intended to give developers and security teams the resources they need to build and maintain secure mobile applications. Through the project, our goal is to classify mobile security risks and provide developmental controls to reduce their impact or likelihood of exploitation.

OWASP - Mobile Security Testing Guide:

The Mobile Security Testing Guide (MSTG) is a comprehensive manual for mobile app security development, testing and reverse engineering.

筱果果 2025-01-25 02:05:46

应确保在互联网上暴露的任何事物。您知道只有您的应用程序会拨打您的API,但是如果不固定API,那么任何人都可以开始调用您的API并假装它们是您的Android应用程序。恶意演员将能够使用该应用程序可以做的所有事情 - 读取用户的数据,修改它们等。HTTPS

也是如此。使用HTTP旨在保护服务器和应用程序之间的流量。不管您只有一个消耗API的应用程序都没关系。如果您不使用HTTP,那么任何人都可以窃听您的流量。

Anything which is exposed on the Internet should be secured. You know that only your app will call your API, but if the API is not secured then anyone can start calling your API and pretend they are your Android app. The malicious actor will be able to do with your API everything that the app could do - read users' data, modify them, etc.

The same goes for HTTPS. Using HTTPS is meant to protect the traffic between your server and your app. It doesn't matter whether you will have only one app consuming the API. If you don't use HTTPS, then anyone can eavesdrop your traffic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文