2018-03-19 05:58:12 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2022-01-04 02:24:25 -06:00
|
|
|
# Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
2018-03-19 05:58:12 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
import os
|
2020-06-22 02:35:13 -05:00
|
|
|
import random
|
|
|
|
import string
|
2018-06-25 08:41:07 -05:00
|
|
|
import sys
|
2019-08-22 04:20:51 -05:00
|
|
|
import time
|
2019-08-28 07:34:08 -05:00
|
|
|
|
2018-03-19 05:58:12 -05:00
|
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
|
from selenium.webdriver.common.by import By
|
2019-11-15 06:32:17 -06:00
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
2019-08-22 04:20:51 -05:00
|
|
|
from selenium.common.exceptions import StaleElementReferenceException, \
|
|
|
|
TimeoutException
|
2018-03-19 05:58:12 -05:00
|
|
|
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
2019-08-22 04:20:51 -05:00
|
|
|
from regression.feature_utils.locators import QueryToolLocators
|
2018-03-19 05:58:12 -05:00
|
|
|
|
|
|
|
|
|
|
|
class CheckFileManagerFeatureTest(BaseFeatureTest):
|
|
|
|
"""Tests to check file manager for XSS."""
|
|
|
|
|
|
|
|
scenarios = [
|
2018-06-25 08:41:07 -05:00
|
|
|
("File manager feature test",
|
2018-03-19 05:58:12 -05:00
|
|
|
dict())
|
|
|
|
]
|
|
|
|
|
|
|
|
def before(self):
|
2018-08-21 07:09:36 -05:00
|
|
|
if os.name == 'nt':
|
|
|
|
self.skipTest("This test is skipped for Windows. As Windows "
|
|
|
|
"does not allow the '<' and '>' character while "
|
|
|
|
"specifying the file name.")
|
|
|
|
|
2018-03-19 05:58:12 -05:00
|
|
|
self.page.add_server(self.server)
|
|
|
|
self.wait = WebDriverWait(self.page.driver, 10)
|
2020-06-22 02:35:13 -05:00
|
|
|
filename = self.server_information['type'] + \
|
|
|
|
str(self.server_information['server_version'])
|
2021-05-27 00:31:25 -05:00
|
|
|
if self.parallel_ui_tests:
|
|
|
|
self.XSS_FILE = '/<img src=x ' + filename + '=alert("1")>.sql'
|
|
|
|
else:
|
|
|
|
self.XSS_FILE = '/tmp/<img src=x ' + filename + '=alert("1")>.sql'
|
2018-03-19 05:58:12 -05:00
|
|
|
# Remove any previous file
|
|
|
|
if os.path.isfile(self.XSS_FILE):
|
|
|
|
os.remove(self.XSS_FILE)
|
|
|
|
|
|
|
|
def after(self):
|
2019-03-21 07:04:37 -05:00
|
|
|
self.page.close_query_tool(False)
|
2018-03-19 05:58:12 -05:00
|
|
|
self.page.remove_server(self.server)
|
|
|
|
|
|
|
|
def runTest(self):
|
2018-06-25 08:41:07 -05:00
|
|
|
print("Tests to check if File manager is vulnerable to XSS... ",
|
|
|
|
file=sys.stderr, end="")
|
2018-03-19 05:58:12 -05:00
|
|
|
self._navigate_to_query_tool()
|
|
|
|
self.page.fill_codemirror_area_with("SELECT 1;")
|
|
|
|
self._create_new_file()
|
|
|
|
self._open_file_manager_and_check_xss_file()
|
2018-06-25 08:41:07 -05:00
|
|
|
print("OK.", file=sys.stderr)
|
|
|
|
|
|
|
|
print("File manager sorting of data", file=sys.stderr)
|
|
|
|
self._check_file_sorting()
|
|
|
|
print("OK.", file=sys.stderr)
|
2018-03-19 05:58:12 -05:00
|
|
|
|
|
|
|
def _navigate_to_query_tool(self):
|
2021-11-10 00:20:20 -06:00
|
|
|
self.page.expand_database_node("Server", self.server['name'],
|
|
|
|
self.server['db_password'],
|
|
|
|
self.test_db)
|
2018-03-19 05:58:12 -05:00
|
|
|
self.page.open_query_tool()
|
|
|
|
|
|
|
|
def _create_new_file(self):
|
2020-05-11 01:41:31 -05:00
|
|
|
self.page.find_by_css_selector(QueryToolLocators.btn_save_file) \
|
2019-07-17 05:45:20 -05:00
|
|
|
.click()
|
2018-03-19 05:58:12 -05:00
|
|
|
# Set the XSS value in input
|
2020-05-21 09:14:28 -05:00
|
|
|
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(
|
|
|
|
(By.CSS_SELECTOR, ".change_file_types")))
|
2019-03-21 07:04:37 -05:00
|
|
|
self.page.find_by_css_selector('.change_file_types')
|
2019-08-22 04:20:51 -05:00
|
|
|
self.page.fill_input_by_css_selector(
|
|
|
|
QueryToolLocators.input_file_path_css, self.XSS_FILE)
|
2018-03-19 05:58:12 -05:00
|
|
|
# Save the file
|
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 05:44:55 -06:00
|
|
|
self.page.click_modal('Create')
|
2018-03-19 05:58:12 -05:00
|
|
|
self.page.wait_for_query_tool_loading_indicator_to_disappear()
|
|
|
|
|
|
|
|
def _open_file_manager_and_check_xss_file(self):
|
2019-08-22 04:20:51 -05:00
|
|
|
load_file = self.page.find_by_css_selector(
|
|
|
|
QueryToolLocators.btn_load_file_css)
|
|
|
|
load_file.click()
|
2020-05-21 09:14:28 -05:00
|
|
|
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(
|
|
|
|
(By.CSS_SELECTOR, ".change_file_types")))
|
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 05:44:55 -06:00
|
|
|
self.page.find_by_css_selector('.change_file_types')
|
2019-08-22 04:20:51 -05:00
|
|
|
self.page.fill_input_by_css_selector(
|
|
|
|
QueryToolLocators.input_file_path_css,
|
2019-11-15 06:32:17 -06:00
|
|
|
"/tmp", key_after_input=Keys.RETURN)
|
2021-05-27 00:31:25 -05:00
|
|
|
time.sleep(2)
|
|
|
|
|
|
|
|
self.wait.until(EC.visibility_of_element_located(
|
|
|
|
(By.CSS_SELECTOR, QueryToolLocators.select_file_content_css)))
|
|
|
|
|
|
|
|
table = self.page.driver.find_element_by_css_selector(
|
|
|
|
QueryToolLocators.select_file_content_css)
|
2018-05-15 09:10:11 -05:00
|
|
|
|
2019-08-22 04:20:51 -05:00
|
|
|
retry_count = 0
|
|
|
|
while retry_count < 5:
|
|
|
|
try:
|
|
|
|
contents = table.get_attribute('innerHTML')
|
|
|
|
break
|
|
|
|
except (StaleElementReferenceException, TimeoutException):
|
|
|
|
retry_count += 1
|
2018-05-15 09:10:11 -05:00
|
|
|
|
2018-03-19 05:58:12 -05:00
|
|
|
self.page.click_modal('Cancel')
|
|
|
|
self.page.wait_for_query_tool_loading_indicator_to_disappear()
|
2020-06-22 02:35:13 -05:00
|
|
|
filename = self.server_information['type'] + \
|
|
|
|
str(self.server_information['server_version'])
|
2018-03-19 05:58:12 -05:00
|
|
|
self._check_escaped_characters(
|
|
|
|
contents,
|
2020-06-22 02:35:13 -05:00
|
|
|
'<img src=x ' + filename +
|
2020-05-11 01:41:31 -05:00
|
|
|
'=alert("1")>.sql', 'File manager'
|
2018-03-19 05:58:12 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
def _check_escaped_characters(self, source_code, string_to_find, source):
|
|
|
|
# For XSS we need to search against element's html code
|
|
|
|
assert source_code.find(
|
|
|
|
string_to_find
|
2019-11-15 06:32:17 -06:00
|
|
|
) != -1, "{0} might be vulnerable to XSS, source code is: {1}".format(
|
|
|
|
source, source_code)
|
2018-06-25 08:41:07 -05:00
|
|
|
|
|
|
|
def _check_file_sorting(self):
|
2019-08-22 04:20:51 -05:00
|
|
|
load_file = self.page.find_by_css_selector(
|
|
|
|
QueryToolLocators.btn_load_file_css)
|
|
|
|
load_file.click()
|
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 05:44:55 -06:00
|
|
|
self.page.find_by_css_selector("#contents th[data-column='0']")
|
2018-06-25 08:41:07 -05:00
|
|
|
|
|
|
|
# Added time.sleep so that the element to be clicked.
|
|
|
|
time.sleep(0.05)
|
2018-08-21 07:09:36 -05:00
|
|
|
|
|
|
|
# Intermittently facing issue on first click it is not successful
|
|
|
|
# so tried couple of times.
|
2019-08-28 07:34:08 -05:00
|
|
|
success = self.page.retry_click(
|
|
|
|
(By.XPATH,
|
|
|
|
"//th[@data-column='0']/div/span[text()='Name']"),
|
|
|
|
(By.CSS_SELECTOR,
|
|
|
|
"#contents th[data-column='0'].tablesorter-headerAsc"))
|
2018-08-21 07:09:36 -05:00
|
|
|
|
|
|
|
if not success:
|
2020-08-07 02:07:00 -05:00
|
|
|
raise RuntimeError("Unable to sort in ascending order while "
|
|
|
|
"clicked on 'Name' column")
|
2019-08-22 04:20:51 -05:00
|
|
|
# Added time.sleep so that the element to be clicked.
|
2018-08-21 07:09:36 -05:00
|
|
|
time.sleep(0.05)
|
2018-06-25 08:41:07 -05:00
|
|
|
|
|
|
|
# Click and Check for sort Descending
|
2018-08-21 07:09:36 -05:00
|
|
|
# Intermittently facing issue on first click it is not successful
|
|
|
|
# so tried couple of times.
|
2019-08-28 07:34:08 -05:00
|
|
|
success = self.page.retry_click(
|
|
|
|
(By.XPATH,
|
|
|
|
"//th[@data-column='0']/div/span[text()='Name']"),
|
|
|
|
(By.CSS_SELECTOR,
|
|
|
|
"#contents th[data-column='0'].tablesorter-headerDesc"))
|
2018-08-21 07:09:36 -05:00
|
|
|
|
|
|
|
if not success:
|
2020-08-07 02:07:00 -05:00
|
|
|
raise RuntimeError("Unable to sort in descending order while "
|
|
|
|
"clicked on 'Name' column")
|
2018-10-17 05:50:22 -05:00
|
|
|
|
|
|
|
self.page.click_modal('Cancel')
|