diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index 845077ac0..bdb66fc1f 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -265,7 +265,7 @@ class URP_Profiles extends UserRightsBaseClassGUI function DoShowGrantSumary($oPage) { - if ($this->GetName() == "Administrator") + if ($this->GetRawName() == "Administrator") { // Looks dirty, but ok that's THE ONE $oPage->p(Dict::S('UI:UserManagement:AdminProfile+')); diff --git a/addons/userrights/userrightsprojection.class.inc.php b/addons/userrights/userrightsprojection.class.inc.php index 408bf478d..08810e389 100644 --- a/addons/userrights/userrightsprojection.class.inc.php +++ b/addons/userrights/userrightsprojection.class.inc.php @@ -97,7 +97,7 @@ class URP_Profiles extends UserRightsBaseClass function DoShowGrantSumary($oPage) { - if ($this->GetName() == "Administrator") + if ($this->GetRawName() == "Administrator") { // Looks dirty, but ok that's THE ONE $oPage->p(Dict::S('UI:UserManagement:AdminProfile+')); diff --git a/application/applicationcontext.class.inc.php b/application/applicationcontext.class.inc.php index 12ea702b1..519e3760e 100644 --- a/application/applicationcontext.class.inc.php +++ b/application/applicationcontext.class.inc.php @@ -163,7 +163,7 @@ class ApplicationContext $sContext = ""; foreach($this->aValues as $sName => $sValue) { - $sContext .= "\n"; + $sContext .= "\n"; } return $sContext; } diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 91483b1f0..76aaade5a 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -581,7 +581,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay $oTemplate = new DisplayTemplate($sTemplate); // Note: to preserve backward compatibility with home-made templates, the placeholder '$pkey$' has been preserved // but the preferred method is to use '$id$' - $oTemplate->Render($oPage, array('class_name'=> MetaModel::GetName(get_class($this)),'class'=> get_class($this), 'pkey'=> $this->GetKey(), 'id'=> $this->GetKey(), 'name' => $this->Get('friendlyname'))); + $oTemplate->Render($oPage, array('class_name'=> MetaModel::GetName(get_class($this)),'class'=> get_class($this), 'pkey'=> $this->GetKey(), 'id'=> $this->GetKey(), 'name' => $this->GetName())); } else { @@ -1473,14 +1473,14 @@ EOF $aEventsList[] ='validate'; $aEventsList[] ='keyup'; $aEventsList[] ='change'; - $sHTMLValue = " {$sValidationField}"; + $sHTMLValue = " {$sValidationField}"; break; case 'DateTime': $aEventsList[] ='validate'; $aEventsList[] ='keyup'; $aEventsList[] ='change'; - $sHTMLValue = " {$sValidationField}"; + $sHTMLValue = " {$sValidationField}"; break; case 'Duration': @@ -1495,7 +1495,7 @@ EOF $sHours = ""; $sMinutes = ""; $sSeconds = ""; - $sHidden = ""; + $sHidden = ""; $sHTMLValue = Dict::Format('UI:DurationForm_Days_Hours_Minutes_Seconds', $sDays, $sHours, $sMinutes, $sSeconds).$sHidden." ".$sValidationField; $oPage->add_ready_script("$('#{$iId}').bind('update', function(evt, sFormId) { return ToggleDurationField('$iId'); });"); break; @@ -1504,7 +1504,7 @@ EOF $aEventsList[] ='validate'; $aEventsList[] ='keyup'; $aEventsList[] ='change'; - $sHTMLValue = " {$sValidationField}"; + $sHTMLValue = " {$sValidationField}"; break; case 'Text': @@ -1528,7 +1528,7 @@ EOF { $sStyle = 'style="'.implode('; ', $aStyles).'"'; } - $sHTMLValue = "
{$sValidationField}
"; + $sHTMLValue = "
{$sValidationField}
"; break; case 'CaseLog': @@ -1553,7 +1553,7 @@ EOF $sPreviousLog = is_object($value) ? $value->GetAsHTML() : ''; $iEntriesCount = is_object($value) ? count($value->GetIndex()) : 0; $sHidden = ""; // To know how many entries the case log already contains - $sHTMLValue = "
$sHeader$sPreviousLog{$sValidationField}
$sHidden
"; + $sHTMLValue = "
$sHeader$sPreviousLog{$sValidationField}
$sHidden
"; $oPage->add_ready_script("$('#$iId').bind('keyup change validate', function(evt, sFormId) { return ValidateCaseLogField('$iId', $bMandatory, sFormId) } );"); // Custom validation function break; @@ -1580,7 +1580,7 @@ EOF } $iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize')); $sHTMLValue = "\n"; - $sHTMLValue .= "\n"; + $sHTMLValue .= "\n"; $sHTMLValue .= "$sFileName
\n"; $sHTMLValue .= " {$sValidationField}\n"; break; @@ -1654,7 +1654,7 @@ EOF } else { - $sHTMLValue = " {$sValidationField}"; + $sHTMLValue = " {$sValidationField}"; $aEventsList[] ='keyup'; $aEventsList[] ='change'; } diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 44ff08c3f..767c0208c 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -1034,7 +1034,7 @@ class HistoryBlock extends DisplayBlock $aValues = array(); foreach($aChanges as $aChange) { - $aValues[] = array('date' => $aChange['date'], 'userinfo' => $aChange['userinfo'], 'log' => ""); + $aValues[] = array('date' => $aChange['date'], 'userinfo' => htmlentities($aChange['userinfo']), 'log' => ""); } $sHtml .= $oPage->GetTable($aAttribs, $aValues); return $sHtml; @@ -1135,7 +1135,7 @@ class MenuBlock extends DisplayBlock $this->AddMenuSeparator($aActions); // Static menus: Email this page & CSV Export $sUrl = ApplicationContext::MakeObjectUrl($sClass, $id); - $aActions['UI:Menu:EMail'] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".$oObj->GetName()."&body=".urlencode($sUrl)); + $aActions['UI:Menu:EMail'] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".urlencode($oObj->GetRawName())."&body=".urlencode($sUrl)); $aActions['UI:Menu:CSVExport'] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "{$sRootUrl}pages/$sUIPage?operation=search&filter=$sFilter&format=csv{$sContext}"); } $this->AddMenuSeparator($aActions); diff --git a/application/loginwebpage.class.inc.php b/application/loginwebpage.class.inc.php index ad622d900..679a00f08 100644 --- a/application/loginwebpage.class.inc.php +++ b/application/loginwebpage.class.inc.php @@ -141,7 +141,6 @@ EOF public function DisplayChangePwdForm($bFailedLogin = false) { $sAuthUser = utils::ReadParam('auth_user', '', false, 'raw_data'); - $sAuthPwd = utils::ReadParam('suggest_pwd', '', false, 'raw_data'); $sVersionShort = Dict::Format('UI:iTopVersion:Short', ITOP_VERSION); $sInconsistenPwdMsg = Dict::S('UI:Login:RetypePwdDoesNotMatch'); diff --git a/application/portalwebpage.class.inc.php b/application/portalwebpage.class.inc.php index 0ce8df78c..77e97603a 100644 --- a/application/portalwebpage.class.inc.php +++ b/application/portalwebpage.class.inc.php @@ -288,7 +288,7 @@ EOF { $aRow = array(); - $aRow['key'] = ''.$oObj->Get('friendlyname').''; + $aRow['key'] = ''.$oObj->GetName().''; $sHilightClass = $oObj->GetHilightClass(); if ($sHilightClass != '') { diff --git a/application/ui.extkeywidget.class.inc.php b/application/ui.extkeywidget.class.inc.php index f64560343..0101aae1d 100644 --- a/application/ui.extkeywidget.class.inc.php +++ b/application/ui.extkeywidget.class.inc.php @@ -133,7 +133,7 @@ class UIExtKeyWidget $aAllowedValues = array(); while($oObj = $oAllowedValues->Fetch()) { - $aAllowedValues[$oObj->GetKey()] = $oObj->Get('friendlyname'); + $aAllowedValues[$oObj->GetKey()] = $oObj->GetName(); } $sHTMLValue = $oPage->GetRadioButtons($aAllowedValues, $value, $this->iId, "{$sAttrFieldPrefix}{$sFieldName}", $bMandatory, $bVertical, $sValidationField); $aEventsList[] ='change'; @@ -159,7 +159,7 @@ class UIExtKeyWidget while($oObj = $oAllowedValues->Fetch()) { $key = $oObj->GetKey(); - $display_value = $oObj->Get('friendlyname'); + $display_value = $oObj->GetName(); if (($oAllowedValues->Count() == 1) && ($bMandatory == 'true') ) { @@ -326,11 +326,11 @@ EOF { throw new Exception('Implementation: null value for allowed values definition'); } - $oValuesSet = new ValueSetObjects($sFilter); + $oValuesSet = new ValueSetObjects($sFilter, 'friendlyname'); // Bypass GetName() to avoid the encoding by htmlentities $aValues = $oValuesSet->GetValues(array('this' => $oObj), $sContains); foreach($aValues as $sKey => $sFriendlyName) { - $oP->add(trim($sFriendlyName)."|".$sKey."\n"); + $oP->add(trim($sFriendlyName)."\t".$sKey."\n"); } } diff --git a/application/uilinkswizard.class.inc.php b/application/uilinkswizard.class.inc.php index b44d5cbfe..d703790f5 100644 --- a/application/uilinkswizard.class.inc.php +++ b/application/uilinkswizard.class.inc.php @@ -85,7 +85,7 @@ class UILinksWizard $sTargetClass = $oAttDef->GetTargetClass(); $oTargetObj = MetaModel::GetObject($sTargetClass, $this->m_iObjectId); - $oP->set_title("iTop - ".MetaModel::GetName($this->m_sLinkedClass)." objects linked with ".MetaModel::GetName(get_class($oTargetObj)).": ".$oTargetObj->GetName()); + $oP->set_title("iTop - ".MetaModel::GetName($this->m_sLinkedClass)." objects linked with ".MetaModel::GetName(get_class($oTargetObj)).": ".$oTargetObj->GetRawName()); $oP->add("
\n"); $oP->add("
\n"); $oP->add("
\n"); diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 3d13c14e1..ba6ebc5de 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -622,7 +622,23 @@ abstract class DBObject return MetaModel::GetClassIcon(get_class($this), $bImgTag); } + /** + * Gets the name of an object in a safe manner for displaying inside a web page + * @return string + */ public function GetName() + { + return htmlentities($this->GetRawName(), ENT_QUOTES, 'UTF-8'); + } + + /** + * Gets the raw name of an object, this is not safe for displaying inside a web page + * since the " < > characters are not escaped and the name may contain some XSS script + * instructions. + * Use this function only for internal computations or for an output to a non-HTML destination + * @return string + */ + public function GetRawName() { return $this->Get('friendlyname'); } diff --git a/core/valuesetdef.class.inc.php b/core/valuesetdef.class.inc.php index e5f3c828c..c4d3877d0 100644 --- a/core/valuesetdef.class.inc.php +++ b/core/valuesetdef.class.inc.php @@ -251,7 +251,7 @@ class ValueSetRelatedObjectsFromLinkSet extends ValueSetDefinition } // #@# or AddObjectArray($aObjects) ? $oSetToCreate = DBObjectSet::FromArray($this->m_sTargetLinkClass, $aLinksToCreate); - $this->m_aValues[$oObject->GetKey()] = $oObject->GetAsHTML($oObject->GetName()); + $this->m_aValues[$oObject->GetKey()] = $oObject->GetName(); } return true; diff --git a/js/extkeywidget.js b/js/extkeywidget.js index c9d7ce057..a2629ace9 100644 --- a/js/extkeywidget.js +++ b/js/extkeywidget.js @@ -354,7 +354,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper if (me.bSelectMode) { // Add the newly created object to the drop-down list and select it - $('