Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#1918 - Remove dubious qfkey checking code that never runs #18007

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions CRM/Core/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,19 @@ public static function validate($key, $name, $addSequence = FALSE) {
}

/**
* @param $key
* The original version of this function, added circa 2010 and untouched
* since then, seemed intended to check for a 32-digit hex string followed
* optionally by an underscore and 4-digit number. But it had a bug where
* the optional part was never checked ever. So have decided to remove that
* second check to keep it simple since it seems like pseudo-security.
*
* @param string $key
*
* @return bool
*/
public static function valid($key) {
// a valid key is a 32 digit hex number
// followed by an optional _ and a number between 1 and 10000
if (strpos('_', $key) !== FALSE) {
list($hash, $seq) = explode('_', $key);

// ensure seq is between 1 and 10000
if (!is_numeric($seq) ||
$seq < 1 ||
$seq > 10000
) {
return FALSE;
}
}
else {
$hash = $key;
}

// ensure that hash is a 32 digit hex number
return (bool) preg_match('#[0-9a-f]{32}#i', $hash);
// ensure that key contains a 32 digit hex string
return (bool) preg_match('#[0-9a-f]{32}#i', $key);
}

}