Skip to content

Commit dd8002f

Browse files
committed
fix(inspector): only a cache command with an int32 id takes effect, and every such id is answered
A Network cache command whose id is not an int32 changed the cache before the main thread rejected it. The socket thread now applies the effect only once the id validates, and replies to valid negative ids as well.
1 parent d2543e9 commit dd8002f

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

‎test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -771,29 +771,29 @@ bool JsV8InspectorClient::handleMessageOnSocketThread(const std::string& message
771771
// and even while paused. A main-session command then continues to the JS
772772
// Network domain handler, if one is registered, for the response. Workers
773773
// have no JS domain handlers, so a worker session is answered here.
774-
if (IsNetworkCacheMethod(method)) {
774+
// Without an int32 id the message is no command: it has no effect and goes
775+
// on to the normal routing below, where V8 rejects it.
776+
long long cacheCommandId = 0;
777+
if (IsNetworkCacheMethod(method) && parsed.contains("id") &&
778+
GetInt32(parsed["id"], cacheCommandId)) {
775779
if (!sessionId.empty()) {
776780
bool knownSession;
777781
{
778782
std::lock_guard<std::mutex> lock(workerTargetsMutex_);
779783
knownSession = workerTargets_.count(sessionId) != 0;
780784
}
781785
if (!knownSession) {
782-
if (msgId >= 0) {
783-
json error = SessionNotFoundReply(msgId, sessionId);
784-
response = JsonDump(error);
785-
}
786+
json error = SessionNotFoundReply(cacheCommandId, sessionId);
787+
response = JsonDump(error);
786788
return true;
787789
}
788790
}
789791
if (method == "Network.clearBrowserCache") {
790792
// A failed clear is answered here, for every session, so the JS
791793
// handler can't report success for it.
792794
if (std::optional<std::string> failure = ClearModuleHttpCacheFromInspector()) {
793-
if (msgId >= 0) {
794-
json error = {{"id", msgId}, {"error", {{"code", -32000}, {"message", *failure}}}};
795-
response = FinishResponse(error, sessionId);
796-
}
795+
json error = {{"id", cacheCommandId}, {"error", {{"code", -32000}, {"message", *failure}}}};
796+
response = FinishResponse(error, sessionId);
797797
return true;
798798
}
799799
} else if (std::optional<bool> cacheDisabled = SetCacheDisabledParam(parsed)) {
@@ -802,10 +802,8 @@ bool JsV8InspectorClient::handleMessageOnSocketThread(const std::string& message
802802
if (sessionId.empty()) {
803803
return false;
804804
}
805-
if (msgId >= 0) {
806-
json reply = NetworkCacheReply(msgId, method, parsed);
807-
response = FinishResponse(reply, sessionId);
808-
}
805+
json reply = NetworkCacheReply(cacheCommandId, method, parsed);
806+
response = FinishResponse(reply, sessionId);
809807
return true;
810808
}
811809

0 commit comments

Comments
 (0)