WebContentUtils

Properties

Link copied to clipboard

A dummy domain used by the AssetLoader for local items. Instead of "file:///", Braze will have the HTML reference this domain for local files. InAppMessageHtmlBaseView.setWebViewContent and InAppMessageWebViewClient.assetLoader should both use this value. Do not use your own value since it is used internally by Braze for HTML In-App messages with a zip file.

Link copied to clipboard
private const val DEFAULT_MAX_UNPACKED_ZIP_ENTRY_COUNT: Int = 1024
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private const val ZIP_EXTENSION: String

Functions

Link copied to clipboard
private fun copyZipEntryToOutputStream(zipInputStream: ZipInputStream, outputStream: BufferedOutputStream, initialTotalUnpackedBytes: Long): Long

Streams the current zip entry to outputStream while enforcing both the per-entry and cumulative archive size limits. Size accounting is performed against actual decompressed bytes read from the stream rather than ZipEntry.getSize, which is attacker-controlled metadata and therefore untrustworthy for zip bomb defense. Throws IOException if maxUnpackedZipEntrySizeBytes or maxUnpackedZipSizeBytes would be exceeded; the caller converts this into a rejected archive.

Link copied to clipboard

Return the Braze html in-app message asset cache directory. This cache directory stores assets for html in-app messages that are not pre-fetched into the files directory.

Link copied to clipboard
fun getLocalHtmlUrlFromRemoteUrl(localDirectory: File, remoteZipUrl: String): String?

Takes a remote url pointing to zip file assets and then downloads them into a local directory.

Link copied to clipboard
private fun hasTooManyZipEntries(entryCount: Int): Boolean

Returns true when entryCount has passed maxUnpackedZipEntryCount. Enforces the SEI CERT IDS04-J TOOMANY guard against archives with an abusive number of entries.

Link copied to clipboard
fun replacePrefetchedUrlsWithLocalAssets(originalString: String, remoteToLocalAssetMap: Map<String, String>): String

In the original string, replaces all instances of the remote uri (Map.Entry.getKey with the local uri Map.Entry.getValue.

Link copied to clipboard
private fun ZipEntry.shouldSkip(): Boolean

Returns true for zip entries that should be silently ignored during extraction. Currently filters __MACOSX metadata entries that macOS adds to archives. Skipped entries do not count toward maxUnpackedZipEntryCount or the cumulative byte total.

Link copied to clipboard
private fun unpackZipEntry(unpackDirectory: String, zipInputStream: ZipInputStream, zipEntry: ZipEntry, totalUnpackedBytes: Long): Long

Validates and extracts a single zip entry under unpackDirectory. Throws IllegalStateException from validateChildFileExistsUnderParent if the entry name would resolve outside of unpackDirectory, and IOException from copyZipEntryToOutputStream if the entry or the cumulative archive exceed their size limits. Directory entries are created; file entries are written to disk.

Link copied to clipboard
fun unpackZipIntoDirectory(unpackDirectory: String, zipFile: File): Boolean

Takes a zip file and unzips it into a destination directory. Creates the destination directory if not already present.

Link copied to clipboard
fun validateChildFileExistsUnderParent(intendedParentDirectory: String, childFilePath: String): String

Validates that the provided filename's canonical path exists under the intended directory. Throws IllegalStateException if not.