Post

Replies

Boosts

Views

Activity

Proper Security when evaluating Javascript from within Swift code
I am currently using the WKWebView to evaluate Javascript in my Swift code. This code uses the callAsyncJavaScript to evaluate Javascript. My code takes parameters from the user and then injects those parameters into the Javascript string that is evaluated by callAsyncJavaScript. This of course is an opportunity for js injection attacks that could cause unwanted js to run. I know Apple uses WebViews in their own native apps like Music. But there is nowhere I can find best practices on how to prevent js injection attacks. Anyone have experience with this? Here's a sample function I use. func createMessage(message: ARMessageDto) async -> ArweaveResult {     do {       guard self.walletStr != nil && !self.walletStr!.isEmpty else {         return Result.failure(TransactionError.General("No wallet exists for this user"))       }       let balance = try await self.arweaveQuerySvc.getBalance()       if balance < 1_000_000_000_000 {         return Result.failure(TransactionError.General("Error wallet balance is less than 1,000,000,000,000 Winston"))       }       guard case .none = message.validate() else {         return Result.failure(TransactionError.ParametersInvalid(message.validate()))       }               let respondingToTransId = message.respondingToTransId ?? ""       let result = try await self.webView!.callAsyncJavaScript("""             \(baseScript!)             const arweaveSvc = main('\(walletStr!)');             const result = await arweaveSvc.createMessage(               '\(message.msg)',               \"\(message.userName)\",               \"\(respondingToTransId)\"             );             return result;           """, contentWorld: WKContentWorld.defaultClient)       _ = await self.arweaveQuerySvc.mine()       return try getTransactionResult(result: result)     } catch {       return Result.failure(TransactionError.General("Failed to create profile"))     }   }
0
0
879
Dec ’21
Make WKWebView invisible or tiny
I need the javascript capabilities that are not provided by JavaScriptCore like fetch and npm, but don't need any UI. Is it possible to make it not visible or at least extremely tiny? I've tried frame .zero and CGRect all zero but it's still fully visible.
1
0
701
Nov ’21
WKWebView: How to load js modules to run with evaluateJavaScript
I have a wkwebview that loads an html file. That file also has script tags for multiple scripts that get loaded as modules. I am trying to run some of the functions inside those modules using evaluateJavaScript, but I cannot either import the respective module or call any of my objects or functions inside the modules. If I create a new function and try running it from evaluateJavaScript that does work. The errors are like "Can't find variable" or "import expects exactly one argument". What am I missing?
0
0
1k
Nov ’21
How does one access a file inside of a XCTestCase class?
I am writing some integration tests and I want to load a file as a Data object. I keep getting the error "couldn't be opened because there is no such file". This is with the file in the same folder as the test class. I also tried creating a new asset catalog into the same project as the test but it also does not work. Here's a few attempts that did not work. let fileUrl = URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)media.png")     let mediaFile = try Data(contentsOf: fileUrl) let fileUrl = URL(fileURLWithPath: FileManager.default.currentDirectoryPath).appendingPathComponent("media.png") let mediaFile = try Data(contentsOf: fileUrl)
2
0
3.1k
Nov ’21
Proper Security when evaluating Javascript from within Swift code
I am currently using the WKWebView to evaluate Javascript in my Swift code. This code uses the callAsyncJavaScript to evaluate Javascript. My code takes parameters from the user and then injects those parameters into the Javascript string that is evaluated by callAsyncJavaScript. This of course is an opportunity for js injection attacks that could cause unwanted js to run. I know Apple uses WebViews in their own native apps like Music. But there is nowhere I can find best practices on how to prevent js injection attacks. Anyone have experience with this? Here's a sample function I use. func createMessage(message: ARMessageDto) async -> ArweaveResult {     do {       guard self.walletStr != nil && !self.walletStr!.isEmpty else {         return Result.failure(TransactionError.General("No wallet exists for this user"))       }       let balance = try await self.arweaveQuerySvc.getBalance()       if balance < 1_000_000_000_000 {         return Result.failure(TransactionError.General("Error wallet balance is less than 1,000,000,000,000 Winston"))       }       guard case .none = message.validate() else {         return Result.failure(TransactionError.ParametersInvalid(message.validate()))       }               let respondingToTransId = message.respondingToTransId ?? ""       let result = try await self.webView!.callAsyncJavaScript("""             \(baseScript!)             const arweaveSvc = main('\(walletStr!)');             const result = await arweaveSvc.createMessage(               '\(message.msg)',               \"\(message.userName)\",               \"\(respondingToTransId)\"             );             return result;           """, contentWorld: WKContentWorld.defaultClient)       _ = await self.arweaveQuerySvc.mine()       return try getTransactionResult(result: result)     } catch {       return Result.failure(TransactionError.General("Failed to create profile"))     }   }
Replies
0
Boosts
0
Views
879
Activity
Dec ’21
Make WKWebView invisible or tiny
I need the javascript capabilities that are not provided by JavaScriptCore like fetch and npm, but don't need any UI. Is it possible to make it not visible or at least extremely tiny? I've tried frame .zero and CGRect all zero but it's still fully visible.
Replies
1
Boosts
0
Views
701
Activity
Nov ’21
WKWebView: How to load js modules to run with evaluateJavaScript
I have a wkwebview that loads an html file. That file also has script tags for multiple scripts that get loaded as modules. I am trying to run some of the functions inside those modules using evaluateJavaScript, but I cannot either import the respective module or call any of my objects or functions inside the modules. If I create a new function and try running it from evaluateJavaScript that does work. The errors are like "Can't find variable" or "import expects exactly one argument". What am I missing?
Replies
0
Boosts
0
Views
1k
Activity
Nov ’21
How does one access a file inside of a XCTestCase class?
I am writing some integration tests and I want to load a file as a Data object. I keep getting the error "couldn't be opened because there is no such file". This is with the file in the same folder as the test class. I also tried creating a new asset catalog into the same project as the test but it also does not work. Here's a few attempts that did not work. let fileUrl = URL(fileURLWithPath: "\(FileManager.default.currentDirectoryPath)media.png")     let mediaFile = try Data(contentsOf: fileUrl) let fileUrl = URL(fileURLWithPath: FileManager.default.currentDirectoryPath).appendingPathComponent("media.png") let mediaFile = try Data(contentsOf: fileUrl)
Replies
2
Boosts
0
Views
3.1k
Activity
Nov ’21