Created
September 1, 2020 04:47
-
-
Save zhuowei/0b7074b3803d72609c028ab5723d9c28 to your computer and use it in GitHub Desktop.
Disable same-origin policy on iOS WKWebView with private API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allows disabling Same-Origin Policy on iOS WKWebView. | |
// Tested on iOS 12.4. | |
// Uses private API; obviously can't be used on app store. | |
@import WebKit; | |
@import ObjectiveC; | |
void WKPreferencesSetWebSecurityEnabled(id, bool); | |
@interface WDBFakeWebKitPointer: NSObject | |
@property (nonatomic) void* _apiObject; | |
@end | |
@implementation WDBFakeWebKitPointer | |
@end | |
void WDBSetWebSecurityEnabled(WKPreferences* prefs, bool enabled) { | |
Ivar ivar = class_getInstanceVariable([WKPreferences class], "_preferences"); | |
void* realPreferences = (void*)(((uintptr_t)prefs) + ivar_getOffset(ivar)); | |
WDBFakeWebKitPointer* fake = [WDBFakeWebKitPointer new]; | |
fake._apiObject = realPreferences; | |
WKPreferencesSetWebSecurityEnabled(fake, enabled); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@zhuowei , from your article ( https://worthdoingbadly.com/disablesameorigin/ ) on this technique, it appears you concluded that invoking
WebKit::WebPreferences::setWebSecurityEnabled
/WKPreferencesSetWebSecurityEnabled
is not possible on MacOS due to missing symbol exports, and that only iOS is viable. Is that correct?