-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent console logging on iOS 11.3+ within WebSocket #18948
Conversation
Generated by 🚫 dangerJS |
@@ -63,6 +84,9 @@ + (void)load | |||
rebind_symbols((struct rebinding[1]){ | |||
{"nwlog_legacy_v", my_nwlog_legacy_v, (void *)&orig_nwlog_legacy_v} | |||
}, 1); | |||
rebind_symbols((struct rebinding[1]){ | |||
{"__nwlog_pack", my__nwlog_pack, (void *)&orig__nwlog_pack}}, | |||
1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you need to fix the indentation here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -19,6 +19,27 @@ | |||
|
|||
#if RCT_DEV // Only supported in dev mode | |||
|
|||
// From https://github.com/apple/swift/blob/ad40c770bfe372f879b530443a3d94761fe258a6/stdlib/public/SDK/os/os_log.m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be necessary to add a __IPHONE_OS_VERSION_MAX_ALLOWED >= 100300
check here since the entire API around this (e.g. _os_log_pack_size
etc.) has only been added in iOS 10.3, but React supports up to iOS 8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
static void my__nwlog_pack(os_log_pack_t pack, os_log_type_t logType) | ||
{ | ||
if (logType == OS_LOG_TYPE_ERROR) { | ||
if (strstr(pack->olp_format, "%{public}s %s Connection has no connected handler") == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're comparing the entire string from start to end anyways I suggest changing this check to:
strcmp(pack->olp_format, "%{public}s %s Connection has no connected handler") != 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I change it to just compare to Connection has no connected handler
, the same as in my_nwlog_legacy_v
@@ -46,7 +67,7 @@ static void my_os_log_error_impl(void *dso, os_log_t log, os_log_type_t type, co | |||
} | |||
} | |||
|
|||
#endif /* __IPHONE_11_0 */ | |||
#endif /* RCT_DEV */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is incorrect. This endif belongs to its previous __IPHONE_11_0
check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, changed back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's my modified version with all required changes I can think of: https://gist.github.com/lhecker/19592f092b2f0611f264733051a168c1
(No attribution needed.)
@lhecker Just addressed the comments, thanks for reviewing. I would suggest we keep the |
{"__nwlog_pack", my__nwlog_pack, (void *)&orig__nwlog_pack}}, | ||
1); | ||
{"__nwlog_pack", my__nwlog_pack, (void *)&orig__nwlog_pack} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly there's still a leftover newline here. 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@maicki Yeah you're right about the |
Oh no... please stop insert hard to debug code here... instead, please remove fishhook at all. See wip patch #17617 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmmulani has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
thanks for this! overall this change looks good to me, the only thing I might fix up is combining the if's to a single one. I'm also a fan of this approach as it's only in dev mode. |
One can say "it's safe because it only in dev mode", but I will say:
|
we want dev mode to be a good experience for people though. Of course we're deviating from prod because we want to make it easy to develop. But I don't think this will cause much unexpected changes for people when comparing debug to prod.
Again, I don't think this is a good reason for us to not make the development experience good. Regarding security, the attack vector would be another native module that you import. At which point, there's not much hope from defending against it. |
separately this got reverted for a build error, I'll try to reland |
Summary: Fixes Xcode console output for web socket connections. Apple uses OSLog for logging within libnetworking starting 11.3+. The old way we hook into logging to prevent it will not work anymore. Let's hook into `__nwlog_pack` that is exclusively used by libnetworking and prevent the logging in there. Closes facebook#18948 Reviewed By: fkgozali Differential Revision: D7940969 Pulled By: mmmulani fbshipit-source-id: a61beea34377044bfad7e3c446b2ec1138d6d1f5
Fixes Xcode console output for web socket connections. Apple uses OSLog for logging within libnetworking starting 11.3+. The old way we hook into logging to prevent it will not work anymore.
Let's hook into
__nwlog_pack
that is exclusively used by libnetworking and prevent the logging in there.