Skip to content

Commit

Permalink
Robustness changes for invalid command payloads in IE to comply with …
Browse files Browse the repository at this point in the history
…W3C Spec
  • Loading branch information
jimevans committed Aug 20, 2018
1 parent e09d7d2 commit ef87df8
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ Json::Value NewSessionCommandHandler::CreateReturnedCapabilities(const IECommand

if (executor.unexpected_alert_behavior().size() > 0) {
capabilities[UNHANDLED_PROMPT_BEHAVIOR_CAPABILITY] = executor.unexpected_alert_behavior();
} else {
capabilities[UNHANDLED_PROMPT_BEHAVIOR_CAPABILITY] = DISMISS_AND_NOTIFY_UNEXPECTED_ALERTS;
}

Json::Value timeouts;
Expand Down
4 changes: 3 additions & 1 deletion cpp/iedriver/IECommandExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ void IECommandExecutor::DispatchCommand() {

if (!this->command_handlers_->IsValidCommand(this->current_command_.command_type())) {
LOG(WARN) << "Unable to find command handler for " << this->current_command_.command_type();
response.SetErrorResponse(501, "Command not implemented");
response.SetErrorResponse(ERROR_UNKNOWN_COMMAND, "Command not implemented");
} else if (!this->current_command_.is_valid_parameters()) {
response.SetErrorResponse(ERROR_INVALID_ARGUMENT, "parameters property of command is not a valid JSON object");
} else {
BrowserHandle browser;
int status_code = WD_SUCCESS;
Expand Down
8 changes: 4 additions & 4 deletions cpp/iedriver/IEDriver.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,14,0,1
PRODUCTVERSION 3,14,0,1
FILEVERSION 3,14,0,2
PRODUCTVERSION 3,14,0,2
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -68,12 +68,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Software Freedom Conservancy"
VALUE "FileDescription", "Driver library for the IE driver"
VALUE "FileVersion", "3.14.0.1"
VALUE "FileVersion", "3.14.0.2"
VALUE "InternalName", "IEDriver.dll"
VALUE "LegalCopyright", "Copyright (C) 2018"
VALUE "OriginalFilename", "IEDriver.dll"
VALUE "ProductName", "Selenium WebDriver"
VALUE "ProductVersion", "3.14.0.1"
VALUE "ProductVersion", "3.14.0.2"
END
END
BLOCK "VarFileInfo"
Expand Down
4 changes: 4 additions & 0 deletions cpp/iedriverserver/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ available via the project downloads page. Changes in "revision" field indicate
private releases checked into the prebuilts directory of the source tree, but
not made generally available on the downloads page.

v3.14.0.2
=========
* Robustness change for invalid command payloads to comply with W3C Spec.

v3.14.0.1
=========
* Updating to properly set the "path" property on cookies when a document
Expand Down
8 changes: 4 additions & 4 deletions cpp/iedriverserver/IEDriverServer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,14,0,1
PRODUCTVERSION 3,14,0,1
FILEVERSION 3,14,0,2
PRODUCTVERSION 3,14,0,2
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -68,12 +68,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Software Freedom Conservancy"
VALUE "FileDescription", "Command line server for the IE driver"
VALUE "FileVersion", "3.14.0.1"
VALUE "FileVersion", "3.14.0.2"
VALUE "InternalName", "IEDriverServer.exe"
VALUE "LegalCopyright", "Copyright (C) 2018"
VALUE "OriginalFilename", "IEDriverServer.exe"
VALUE "ProductName", "Selenium WebDriver"
VALUE "ProductVersion", "3.14.0.1"
VALUE "ProductVersion", "3.14.0.2"
END
END
BLOCK "VarFileInfo"
Expand Down
Binary file modified cpp/prebuilt/Win32/Release/IEDriverServer.exe
Binary file not shown.
Binary file modified cpp/prebuilt/x64/Release/IEDriverServer.exe
Binary file not shown.
2 changes: 2 additions & 0 deletions cpp/webdriver-server/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ void Command::Deserialize(const std::string& json) {
}
}

this->is_valid_parameters_ = true;
Json::Value command_parameter_object = root["parameters"];
if (!command_parameter_object.isObject()) {
LOG(WARN) << "The value of the 'parameters' attribute is not a JSON "
<< "object. This is invalid for the WebDriver JSON Wire "
<< "Protocol.";
this->is_valid_parameters_ = false;
} else {
it = command_parameter_object.begin();
end = command_parameter_object.end();
Expand Down
3 changes: 3 additions & 0 deletions cpp/webdriver-server/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Command {
void Deserialize(const std::string& json);

std::string command_type(void) const { return this->command_type_; }
bool is_valid_parameters(void) const { return this->is_valid_parameters_; }
ParametersMap command_parameters(void) const {
return this->command_parameters_;
}
Expand All @@ -45,6 +46,8 @@ class Command {
std::string command_type_;
// Session ID for this command.
std::string session_id_;
// Flag indicating that parameters were valid.
bool is_valid_parameters_;
// Command parameters passed as JSON in the body of the request.
ParametersMap command_parameters_;

Expand Down
4 changes: 1 addition & 3 deletions cpp/webdriver-server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ std::string Server::ReadRequestBody(struct mg_connection* conn,
break;
}
}
if (content_length == 0) {
request_body = "{}";
} else {
if (content_length != 0) {
std::vector<char> buffer(content_length + 1);
int bytes_read = 0;
while (bytes_read < content_length) {
Expand Down

0 comments on commit ef87df8

Please sign in to comment.