diff --git a/Sources/FormbricksSDK/WebView/FormbricksViewModel.swift b/Sources/FormbricksSDK/WebView/FormbricksViewModel.swift index 9500c14..3728a2b 100644 --- a/Sources/FormbricksSDK/WebView/FormbricksViewModel.swift +++ b/Sources/FormbricksSDK/WebView/FormbricksViewModel.swift @@ -10,7 +10,12 @@ final class FormbricksViewModel: ObservableObject { self.surveyId = surveyId if let webviewDataJson = WebViewData(workspaceResponse: workspaceResponse, surveyId: surveyId).getJsonString(), let surveyScriptUrl = FormbricksWorkspace.surveyScriptUrlString { - htmlString = htmlTemplate.replacingOccurrences(of: "{{WEBVIEW_DATA}}", with: webviewDataJson) + // Base64-encode the payload before injecting it into the HTML. Base64 output is + // limited to [A-Za-z0-9+/=], so survey content can no longer contain characters + // (backticks, `${...}`, quotes) that would break out of the surrounding JS string + // literal and execute as code. The WebView decodes it back to JSON at runtime. + let webviewDataBase64 = Data(webviewDataJson.utf8).base64EncodedString() + htmlString = htmlTemplate.replacingOccurrences(of: "{{WEBVIEW_DATA}}", with: webviewDataBase64) .replacingOccurrences(of: "{{SURVEY_SCRIPT_URL}}", with: surveyScriptUrl) } } @@ -33,7 +38,9 @@ private extension FormbricksViewModel {