-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(files): mitigate issues with special chars in file names
Relative paths to files that contain special characters in the name will now be encoded with base64 to avoid malformatted URLs and HMAC mismatches resulting from unescaped characters. URLs generated prior to this change will continue working. Refs #10608
- Loading branch information
1 parent
11c4640
commit 4a7b74e
Showing
5 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
namespace Elgg\Security; | ||
|
||
/** | ||
* Encode and decode Base 64 URL | ||
* | ||
* @access private | ||
*/ | ||
class Base64Url { | ||
|
||
/** | ||
* Encode base 64 URL | ||
* | ||
* @param string $bytes Bytes to encode | ||
* @return string | ||
*/ | ||
public static function encode($bytes) { | ||
$bytes = base64_encode($bytes); | ||
$bytes = rtrim($bytes, '='); | ||
return strtr($bytes, '+/', '-_'); | ||
} | ||
|
||
/** | ||
* Decode base 64 URL | ||
* | ||
* @param string $bytes Bytes to decode | ||
* @return string|false | ||
*/ | ||
public static function decode($bytes) { | ||
$bytes = strtr($bytes, '-_', '+/'); | ||
return base64_decode($bytes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters