Skip to main content
Version: 3.x.x

Security

Custom Base URL & Certificate Pinning​

For enterprise deployments, you can configure a custom base URL (for custom domains/proxies) and implement certificate pinning for enhanced security:

StorifyMeSDK.initialize(
accountId: "ACCOUNT_ID",
apiKey: "API_KEY",
environment: .EU,
customBaseUrl: "https://stories.yourapp.com/", // Optional: custom domain/proxy
certificatePins: [ // Optional: SHA-256 public key pins
"sha256/YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="
]
)
tip

Both parameters are optional and independent. See the Complete Guide for detailed instructions, security best practices, and how to obtain certificate pins.

Content Integrity Verification​

For accounts with content signing enabled, pass your PEM-encoded ECDSA P-256 public keys during initialization. The array can contain multiple keys during key rotation.

let publicKeys = ["YOUR_PEM_ENCODED_ECDSA_P256_PUBLIC_KEY"]

StorifyMeSDK.initialize(
accountId: "YOUR_ACCOUNT_ID",
apiKey: "YOUR_API_KEY",
environment: .EU,
integrityPublicKeys: publicKeys
)

When keys are configured, each returned experience must carry a valid signature or the SDK drops it before rendering. Without keys, verification is disabled. Assign a StorifyMeWidgetDelegate before loading the widget to observe rejected content through onIntegrityFailed(storyID:reason:); see iOS events.

Custom Gateway Request Headers​

If your custom gateway requires an app-owned session header, register the request interceptor before initializing the SDK. It runs synchronously for each stories, base-template, audience, and ads content API request routed through customBaseUrl, so the app can provide a refreshed token on every request. The callback receives the absolute request URL and current headers, including accountId; return the complete header map to send.

StorifyMeSDK.requestInterceptor = { url, headers in
var requestHeaders = headers
requestHeaders["Authorization"] = "Bearer \(session.currentToken())"
return requestHeaders
}

StorifyMeSDK.initialize(
accountId: "YOUR_ACCOUNT_ID",
apiKey: "YOUR_API_KEY",
environment: .EU,
customBaseUrl: "https://gateway.example.com"
)

The interceptor only applies to content API requests using the configured custom base URL. It does not add headers to media or WebView traffic. The SDK does not store or log returned header values. If the callback throws, the request fails. Keep it synchronous and make sure the gateway does not redirect requests to a different origin; the SDK does not reapply headers after redirects.

Set StorifyMeSDK.requestInterceptor = nil to unregister the callback.

Private Certificate Authority (CA)​

If the customBaseUrl host uses a private CA, add the public X.509 CA certificate to your app bundle and pass its DER-encoded data through trustedCACertificates. Device-wide CA installation is not required. Do not include the CA's private key in the app.

Add the .der file to the iOS app target's bundle resources, then load and pass it during initialization:

import Foundation
import StorifyMe

guard let caURL = Bundle.main.url(forResource: "partner_root_ca", withExtension: "der"),
let caData = try? Data(contentsOf: caURL) else {
fatalError("partner_root_ca.der is missing from the app bundle")
}

StorifyMeSDK.initialize(
accountId: "YOUR_ACCOUNT_ID",
apiKey: "YOUR_API_KEY",
environment: .EU,
customBaseUrl: "https://stories.example.com/api/",
certificatePins: ["sha256/YOUR_BASE64_SPKI_HASH="], // Optional
trustedCACertificates: [caData]
)

If the CA file you receive is a single PEM certificate, convert it to DER before adding it to the app bundle:

openssl x509 -in partner_root_ca.pem -outform DER -out partner_root_ca.der

The SDK adds the supplied CA to TLS trust for the exact hostname in customBaseUrl; system CAs remain trusted. It still validates the certificate chain and hostname. When certificatePins is provided, the SDK checks the configured SPKI pins after TLS validation succeeds. The CA parameter does not change device-wide trust or apply to unrelated hosts. SDK-managed media and WebView requests use this trust handling when they target the same configured hostname; a different CDN hostname must use its own normal trust configuration.

If App Transport Security (ATS) still rejects the custom trust flow, add an exception for only the custom hostname to the app's Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>stories.example.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>

This ATS key also permits plain HTTP to that hostname. Keep the exception domain-specific and continue using the SDK's CA and pin validation for HTTPS. Apple requires an App Store review justification when this key is enabled. See Apple's documentation.