Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mahara
mahara
Commits
6b82e549
Commit
6b82e549
authored
Oct 30, 2017
by
Robert Lyon
Committed by
Gerrit Code Review
Oct 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge "Security bug 1719491: Stop user saving bad first/last/preferred name" into 15.04_STABLE
parents
596e2674
e94cf694
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
5 deletions
+55
-5
htdocs/artefact/internal/lib.php
htdocs/artefact/internal/lib.php
+4
-3
htdocs/auth/lib.php
htdocs/auth/lib.php
+8
-1
htdocs/lang/en.utf8/pieforms.php
htdocs/lang/en.utf8/pieforms.php
+1
-1
htdocs/lib/pieforms/pieform/rules/safetext.php
htdocs/lib/pieforms/pieform/rules/safetext.php
+42
-0
No files found.
htdocs/artefact/internal/lib.php
View file @
6b82e549
...
...
@@ -481,11 +481,12 @@ class ArtefactTypeProfile extends ArtefactType {
}
public
static
function
get_field_element_data
()
{
// we make sure the first/last/preferred names are safe as they get used in emails sent out
return
array
(
'firstname'
=>
array
(
'rules'
=>
array
(
'maxlength'
=>
50
)),
'lastname'
=>
array
(
'rules'
=>
array
(
'maxlength'
=>
50
)),
'firstname'
=>
array
(
'rules'
=>
array
(
'maxlength'
=>
50
,
'safetext'
=>
true
)),
'lastname'
=>
array
(
'rules'
=>
array
(
'maxlength'
=>
50
,
'safetext'
=>
true
)),
'studentid'
=>
array
(
'rules'
=>
array
(
'maxlength'
=>
50
)),
'preferredname'
=>
array
(
'rules'
=>
array
(
'maxlength'
=>
50
)),
'preferredname'
=>
array
(
'rules'
=>
array
(
'maxlength'
=>
50
,
'safetext'
=>
true
)),
);
}
...
...
htdocs/auth/lib.php
View file @
6b82e549
...
...
@@ -816,6 +816,7 @@ function auth_check_required_fields() {
require_once
(
'pieforms/pieform.php'
);
$alwaysmandatoryfields
=
array_keys
(
ArtefactTypeProfile
::
get_always_mandatory_fields
());
$element_data
=
ArtefactTypeProfile
::
get_field_element_data
();
foreach
(
ArtefactTypeProfile
::
get_mandatory_fields
()
as
$field
=>
$type
)
{
// Always mandatory fields are stored in the usr table, so are part of
// the user session object. We can save a query by grabbing them from
...
...
@@ -842,6 +843,11 @@ function auth_check_required_fields() {
'title'
=>
get_string
(
$field
,
'artefact.internal'
),
'rules'
=>
array
(
'required'
=>
true
)
);
// We need to merge the rules for the element if they have special rules defined
// in get_field_element_data() so that we save correct data.
if
(
isset
(
$element_data
[
$field
]))
{
$elements
[
$field
]
=
array_merge_recursive
(
$elements
[
$field
],
$element_data
[
$field
]);
}
if
(
$field
==
'socialprofile'
)
{
$elements
[
$field
]
=
ArtefactTypeSocialprofile
::
get_new_profile_elements
();
...
...
@@ -964,9 +970,10 @@ function requiredfields_validate(Pieform $form, $values) {
}
}
}
// Check if email has been taken
if
(
isset
(
$values
[
'email'
])
&&
record_exists
(
'artefact_internal_profile_email'
,
'email'
,
$values
[
'email'
]))
{
$form
->
set_error
(
'email'
,
get_string
(
'unvalidatedemailalreadytaken'
,
'artefact.internal'
));
$form
->
set_error
(
'email'
,
get_string
(
'unvalidatedemailalreadytaken'
,
'artefact.internal'
));
}
// Check if the socialprofile url is valid.
if
(
isset
(
$values
[
'socialprofile_hidden'
])
&&
$values
[
'socialprofile_hidden'
]
&&
$values
[
'socialprofile_profiletype'
]
==
'webpage'
&&
!
filter_var
(
$values
[
'socialprofile_profileurl'
],
FILTER_VALIDATE_URL
))
{
...
...
htdocs/lang/en.utf8/pieforms.php
View file @
6b82e549
...
...
@@ -65,7 +65,7 @@ $string['rule.minvalue.minvalue'] = 'This value cannot be smaller than %d.';
$string
[
'rule.regex.regex'
]
=
'This field is not in valid form.'
;
$string
[
'rule.required.required'
]
=
'This field is required.'
;
$string
[
'rule.safetext.invalidchars'
]
=
'This field has invalid characters.'
;
$string
[
'rule.validateoptions.validateoptions'
]
=
'The option "%s" is invalid.'
;
$string
[
'rule.maxvalue.maxvalue'
]
=
'This value cannot be larger than %d.'
;
htdocs/lib/pieforms/pieform/rules/safetext.php
0 → 100644
View file @
6b82e549
<?php
/**
* Pieforms: Advanced web forms made easy
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package pieform
* @subpackage rule
* @author Robert Lyon <robertl@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
/**
* Checks whether the field has a safe text string.
*
* @param Pieform $form The form the rule is being applied to
* @param string $value The value of the field
* @param array $element The element to check
* @param string $check Whether to check the element
* @return string The error message, if the value is invalid.
*/
function
pieform_rule_safetext
(
Pieform
$form
,
$value
,
$element
,
$check
)
{
if
(
$value
!=
''
)
{
if
(
$value
!=
strip_tags
(
clean_html
(
$value
)))
{
return
$form
->
i18n
(
'rule'
,
'safetext'
,
'invalidchars'
,
$element
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment