在 url 中使用 codeigniter 的 base64 编码字符串

发布于 2024-11-17 18:39:17 字数 1017 浏览 5 评论 0原文

我有一个加密的、base64 编码的数组,我需要将其放入 url 中并插入到我们发送给客户端的电子邮件中,以便能够(唯一地)识别它们 - 问题是 base64_encode() 经常在它之后附加一个或两个 = 符号字符串,默认情况下 CI 不允许使用。

这是一个例子: <一href="http://example.com/cec/pay_invoice/VXpkUmJnMWxYRFZWTEZSd0RXZFRaMVZnQWowR2N3TTdEVzR DZGdCbkQycFFaZ0JpQmd4V09RRmdWbkVMYXdZbUJ6OEdZQVJ1QlNJTU9Bb3RWenNFSmxaaFVXcFZaMXQxQXpWV1BR QThVVEPUT0ZFZ0RRbGNabFV6VkNFTlpsTWxWV29DTmdackEzQU5Nd0lpQURNUGNGQS9BRFlHWTFacUFTWldOZ3M5 QmpRSGJBWTlCREVGWkF4V0NtQlhiZ1IzVm1CUk9sVm5XMllEWlZaaEFHeFJZMU51VVdNTmJsdzNWVzlVT0EwZw==" rel="noreferrer">http://example.com/cec/pay_invoice/VXpkUmJnMWxYRFZWTEZSd0RXZFRaMVZnQWowR2N3 TTDEVzRDZGdCbkQycFFaZ0JpQmd4V09RRmdWbkVMYXdZbUJ6OEdZQVJ1QlNJTU9Bb3RWenNFSmxaaFVXcFZaMXQxQXpW V1BRQThVVEpUT0ZFZ0RRbGNabFV6VkNFTlpsTWxWV29DTmdackEzQU5Nd0lpQURNUGNGQS9BRFlHWTFacUFTWldOZ3M5 QmpRSGJBWTlCREVGWkF4V0NtQlhiZ1IzVm1CUk9sVm5XMllEWlZaaEFHeFJZMU51VVdNTmJsdzNWVzlVT0EwZw==

现在我知道我可以在 config.php 中允许 = 符号,但我不完全理解这样做的安全隐患(它一定是出于某种原因而被禁用的,对吗?)

有谁知道为什么这可能是一个坏主意允许在 URL 中使用 = 符号吗?

谢谢! 约翰.

I have an encrypted, base64 encoded array that I need to put into a url and insert into emails we send to clients to enable them to be identified (uniquely) - the problem is that base64_encode() often appends an = symbol or two after it's string of characters, which by default is disallowed by CI.

Here's an example:
http://example.com/cec/pay_invoice/VXpkUmJnMWxYRFZWTEZSd0RXZFRaMVZnQWowR2N3TTdEVzRDZGdCbkQycFFaZ0JpQmd4V09RRmdWbkVMYXdZbUJ6OEdZQVJ1QlNJTU9Bb3RWenNFSmxaaFVXcFZaMXQxQXpWV1BRQThVVEpUT0ZFZ0RRbGNabFV6VkNFTlpsTWxWV29DTmdackEzQU5Nd0lpQURNUGNGQS9BRFlHWTFacUFTWldOZ3M5QmpRSGJBWTlCREVGWkF4V0NtQlhiZ1IzVm1CUk9sVm5XMllEWlZaaEFHeFJZMU51VVdNTmJsdzNWVzlVT0EwZw==

Now I understand I can allow the = sign in config.php, but I don't fully understand the security implications in doing so (it must have been disabled for a reason right?)

Does anyone know why it might be a bad idea to allow the = symbol in URLs?

Thanks!
John.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

千紇 2024-11-24 18:39:17

不确定为什么不允许使用 =,但您也可以省略等号。

$base_64 = base64_encode($data);
$url_param = rtrim($base_64, '=');
// and later:
$base_64 = $url_param . str_repeat('=', strlen($url_param) % 4);
$data = base64_decode($base_64);

Base64 规范只允许在字符串末尾添加 = 符号,并且它们纯粹用作填充,不会丢失数据。

编辑:它可能不允许将此作为​​兼容性选项。从安全角度来看,我无法想到任何原因,但它有可能会扰乱工具链中某处的查询字符串解析。

Not sure why = is disallowed, but you could also leave off the equals signs.

$base_64 = base64_encode($data);
$url_param = rtrim($base_64, '=');
// and later:
$base_64 = $url_param . str_repeat('=', strlen($url_param) % 4);
$data = base64_decode($base_64);

The base64 spec only allows = signs at the end of the string, and they are used purely as padding, there is no chance of data loss.

Edit: It's possible that it doesn't allow this as a compatibility option. There's no reason that I can think of from a security perspective, but there's a possibility that it may mess with query string parsing somewhere in the tool chain.

欢烬 2024-11-24 18:39:17

请将字符“=”添加到 config.php 文件中的 $config['permissed_uri_chars'] 中,您可以在 application/config 文件夹中找到该文件

Please add the character "=" to $config['permitted_uri_chars'] in your config.php file you can find that file at application/config folder

心意如水 2024-11-24 18:39:17

原本该网址中根本不存在任何有害字符。但没有经验丰富的开发人员或编写糟糕的软件可以帮助某些角色变得邪恶。

截至 = - 我没有发现在网址中使用它有任何问题

Originally there are no any harmful characters in the url at all. But there are not experienced developers or bad-written software that helps some characters to become evil.

As of = - I don't see any issues with using it in urls

回梦 2024-11-24 18:39:17

您可以使用本机 php 的 urlencode 和 urldecode 函数,而不是更新配置文件。

$str=base64_encode('test');
$url_to_be_send=urlencode($str);
//send it via url

//now on reciveing side

//assuming value passed via get is stored in $encoded_str

$decoded_str=base64_decode(urldecode($encoded_str));

Instead of updating config file you can use urlencode and urldecode function of native php.

$str=base64_encode('test');
$url_to_be_send=urlencode($str);
//send it via url

//now on reciveing side

//assuming value passed via get is stored in $encoded_str

$decoded_str=base64_decode(urldecode($encoded_str));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文