spomky-labs/base64url
Fast RFC 4648 Base64 URL-safe encoder/decoder for PHP. Lightweight library to encode/decode URL-safe Base64 strings with high performance, compatible with PHP 7.1+. Ideal for JWT, web tokens, and URL parameters.
spomky-labs/base64url package (v2.0.4) remains critical for URL-safe Base64 in Laravel, addressing:
+/=/=).Illuminate\Support\Facades\Crypt).Illuminate\Encryption\Encrypter).Str::of()->base64()).Base64Url::encode()).Str helper or custom UrlSafeBase64 helper.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Deprecation | Last active release in 2020 (v2.0.4 is a minor update only). | Fork/maintain or switch to paragonie/base64-url (actively maintained). |
| Security | No vulnerabilities reported; .gitattributes update (v2.0.4) is cosmetic. |
Audit against OWASP Base64 risks (e.g., padding oracle attacks). |
| Edge Cases | May still struggle with binary data or non-ASCII inputs. | Test with Laravel’s Crypt/Hash functions for consistency. |
| Backward Compatibility | Laravel’s Str::base64() uses standard Base64 (not URL-safe). |
Document breaking changes if replacing existing logic. |
Hash, Crypt, or Sanctum/Passport for tokens?paragonie/base64-url (actively maintained) replace this with zero refactoring?| Laravel Component | Integration Strategy |
|---|---|
| Service Container | Bind via Base64Url::class in a Service Provider. |
| Facades | Create Base64Url facade for global access (e.g., Base64Url::encode($data)). |
| Helpers | Extend Str helper with Str::base64UrlEncode() via macros. |
| Encryption Layer | Hook into Illuminate\Encryption\Encrypter for token encoding. |
| API Responses | Use for URL-safe tokens in JSON API responses. |
| Storage/Redis | Encode keys to avoid +/= conflicts in URLs. |
composer require spomky-labs/base64url:^2.0.use SpomkyLabs\Base64Url\Base64Url;
$encoder = new Base64Url();
$encoded = $encoder->encode('test'); // "dGVzdA"
$this->app->bind(Base64Url::class, function () {
return new \SpomkyLabs\Base64Url\Base64Url();
});
app/Facades/Base64Url.php).Str helper:
Str::macro('base64UrlEncode', fn($value) => app(Base64Url::class)->encode($value));
base64_encode() calls needing URL safety.Base64Url::encode().| Compatibility Check | Status |
|---|---|
| PHP 8.0+ | ✅ No breaking changes. |
| Laravel 7+ | ✅ Framework-agnostic. |
| Composer Autoload | ✅ PSR-4 compliant. |
| Binary Data | ⚠️ Test with random_bytes() or file_get_contents(). |
| Non-ASCII Strings | ⚠️ May need mb_encode_mimeheader() preprocessing. |
| Task | Effort | Owner |
|---|---|---|
| Dependency Updates | Low | DevOps/TPM |
| Security Patches | Low | TPM (or fork) |
| Laravel Version Support | Low | TPM (test upgrades) |
| Documentation | Medium | Tech Writer/TPM |
+/= in input.dd(app(Base64Url::class)->decode($token)).base64_encode() + str_replace() for critical systems.rtrim(base64_encode(), '=').| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package Deprecation | Breaking changes in Laravel 9+ | Fork or switch to paragonie/.... |
| Encoding Mismatch | API tokens rejected | Validate with preg_match('/^[A-Za-z0-9_-]+$/', $token). |
| Binary Data Corruption | Storage/Redis keys broken | Pre-process with base64_encode(). |
| PHP Version Issues | Fails on PHP 8.2+ | Test early in CI pipeline. |
| Role | Training Needed |
|---|---|
| Backend Devs | - Usage of Base64Url facade/helpers. |
- When to prefer over base64_encode(). |
|
| QA Engineers | - Test edge cases (binary data, empty strings). |
| DevOps | - Composer dependency updates. |
| Product Owners | - Business impact of URL-safe tokens (e.g., deep linking, API stability). |
Base64Url::encode() with:
str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($data));
config/base64url.php) for gradual rollback.Key Update from v2.0.4:
.gitattributes update is cosmetic).How can I help you explore Laravel packages today?