> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/merchant-tokenization/ja/sdk-tong-he/security/ios.md).

# iOS

## IOS01. センシティブデータ漏洩の防止 <a href="#ios01-preventing-sensitive-data-leaks" id="ios01-preventing-sensitive-data-leaks"></a>

アプリケーションライフサイクルでセンシティブデータを管理するために次の方法を使用してください：

* `applicationWillResignActive`: 画面上の表示を消去し、表示されたセンシティブデータを暗号化するため。表示を消去するには、表示された内容を隠すために次のコードを使用できます：

```swift
UIApplication.shared.keyWindow.hidden = true
```

* `applicationDidBecomeActive`: センシティブデータを表示および復号化するため。
* `UIScreenCapturedDidChangeNotification`: 画面録画を検出するため。アプリケーションは表示を消去し、あらゆるセンシティブデータを暗号化する必要があります。

## IOS02. Xcode出力からシンボルを削除 <a href="#ios02-remove-symbols-from-xcode-output" id="ios02-remove-symbols-from-xcode-output"></a>

アプリケーションはリリース用最終バイナリからすべてのシンボルを削除する必要があります。

デバッグ情報やその他のシンボルを削除するために、Xcodeプロジェクトで次の設定を行うことが推奨されます：

```swift
DEPLOYMENT_POSTPROCESSING = YES
GCC_GENERATE_DEBUGGING_SYMBOLS = NO
STRIP_INSTALLED_PRODUCT = YES
STRIP_STYLE = all
COPY_PHASE_STRIP = YES
```

## IOS03. Swiftにおけるセンシティブデータの管理 <a href="#ios03-management-of-sensitive-data-in-swift" id="ios03-management-of-sensitive-data-in-swift"></a>

アプリケーションはすべてのセンシティブデータが適切に管理されていることを保証する必要があります。値型である [Data](https://developer.apple.com/documentation/foundation/data) はSwiftであるため、データに割り当てられた追加のポインタは割り当てられたバイトの新しいコピーを生じさせます。

そのような操作は割り当てられるセンシティブなバイト数を軽減するために最小限にするべきです。

割り当てられたバイトは `inout` 引数として渡して参照渡しにし、使用が完了したら消去することができます。

次のコードスニペットは割り当てられたバイトを `inout` 引数として渡す方法を示します：

```swift
func helloWorld(_ data: inout Data) {
	...
}

var data = Data()
helloWorld(&data)
```

次のコードスニペットは変数を消去する方法を示します： `Data` variable:

```swift
extension Data {
    internal mutating func wipe() {
        guard count > 0 else {
            return
        }
        let length = count
        withUnsafeMutableBytes { ptr in
            if let mutableRawPtr = ptr.baseAddress {
                memset_s(mutableRawPtr, length, 0, length)
            }
        }
    }
}
```

## IOS04. センシティブ入力の自動補正キャッシュを無効化 <a href="#ios04-disable-auto-correction-cache-for-sensitive-input" id="ios04-disable-auto-correction-cache-for-sensitive-input"></a>

アプリケーションは、センシティブなデータを要求する入力について自動補正キャッシュを無効にする必要があります。これにより、デバイスにアクセスできる攻撃者がオートコンプリートで提案された文字列を使用してセンシティブなテキスト入力データを閲覧することを防ぎます。

アプリケーションは自動補正キャッシュを無効にするために次のいずれかの操作を実行できます：

* 次のプロパティを設定します： `secureTextEntry` フィールドを `true`.
* 次のプロパティを設定します： `autoCorrectionType` フィールドを `UITextAutocorrectionType.no`.

## IOS05. センシティブデータのコピー/貼り付けを無効化 <a href="#ios05-disable-data-copypaste-for-sensitive-data" id="ios05-disable-data-copypaste-for-sensitive-data"></a>

アプリケーションはセンシティブデータのコピー/貼り付けメニューを無効にする必要があります。これにより、デバイスにアクセスできる攻撃者がコピーされたデータを貼り付けて閲覧することを防ぎます。次のサンプルコードはコピー/貼り付けメニューを無効にします：

```swift
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    let menuController = UIMenuController.shared
    menuController.isMenuVisible = false
}
```

## IOS06. App Storeでのアプリバージョン管理 <a href="#ios06-managing-app-versions-in-the-app-store" id="ios06-managing-app-versions-in-the-app-store"></a>

ユーザーは既に購入またはインストール済みの以前のアプリバージョンを再ダウンロードできるため、古いデバイスで現在のバージョンがサポートされなくなった場合でも顧客がアプリを使用できる可能性があります。これらのバージョンを利用可能にしたくない場合は、App Store Connectの「Manage Your Apps」モジュールの「Rights and Pricing」セクションでアプリの以前のバージョンの可用性を管理できます。

詳細については、次を参照してください： [AppStore Connect](https://developer.apple.com/support/app-store-connect/).

セキュリティの観点からは、攻撃対象をできるだけ小さく保つことが推奨されます。古いバージョンを維持するとより広いユーザーに届きますが、既にセキュリティが破られている可能性のある古いファームウェアに晒されるリスクもあります。可能であれば、1つのバージョン（最新のもの）を公開し、代わりにビルド設定でより広いiOSバージョンをサポートするように構成するのが最良です。

**デプロイメントターゲットでアプリの「Simulator」を無効にする**

デプロイメントターゲットにはiOSデバイスのみを含めるべきです。

**App Store Connectでアプリの「Apple Silicon Mac Availability」を無効にする**

Mac M1上でiOSアプリを実行することは、アプリケーションのバイナリやサンドボックスデータにアクセスしやすいため、はるかに安全性が低くなります。

インストールをM1 Macで許可しないようにするために、リスクを低減するためにApp Store Connectでアプリの「Apple Silicon Mac Availability」を無効にしてください。

「Apple Silicon Mac Availability」を無効にする方法の詳細については、Appleの文書を参照してください： [ここ](https://developer.apple.com/documentation/apple-silicon/running-your-ios-apps-on-macos)

## IOS07. アプリケーション改ざんの防止 <a href="#ios07-preventing-the-tampering-of-the-application" id="ios07-preventing-the-tampering-of-the-application"></a>

アプリケーションコードへの悪意あるハッキングを防ぐために、実行時にアプリケーションのバイナリの整合性を検証することが推奨されます。これは、\_\_TEXTセグメントの\_\_textセクションのチェックサムを計算することでアプリケーション内に実装できます。

実装の詳細については、次を参照してください： [github link](https://github.com/OWASP/owasp-mstg/blob/master/Document/0x06j-Testing-Resiliency-Against-Reverse-Engineering.md)チェックサムを計算するコードを保護するためには強力な難読化が必要です。

改ざん攻撃に関するリスクについては、次のOWASPのリンクを確認してください： [OWASP link](https://www.owasp.org/index.php/Mobile_Top_10_2016-M8-Code_Tampering).

## IOS08. Xcodeコンパイラのセキュリティおよび難読化オプション <a href="#ios08-xcode-compiler-security-and-obfuscation-options" id="ios08-xcode-compiler-security-and-obfuscation-options"></a>

アプリケーションは逆アセンブルをより複雑にしてセキュリティを高め、難読化を提供するXcodeオプションを使用する必要があります。

Xcodeプロジェクトで次の設定を行うことが推奨されます：

```swift
GCC_UNROLL_LOOPS = YES
GCC_OPTIMIZATION_LEVEL = 3
OTHER_CFLAGS = -fstack-protector-all -finline-functions
CLANG_ENABLE_OBJC_ARC = YES
GCC_DYNAMIC_NO_PIC = NO
LD_NO_PIE = NO
RUN_CLANG_STATIC_ANALYZER = YES
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_GETPW_GETS = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_MKSTEMP = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_VFORK = YES
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/merchant-tokenization/ja/sdk-tong-he/security/ios.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
