承接 glaivepro/hidevara 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

glaivepro/hidevara

Composer 安装命令:

composer require glaivepro/hidevara

包简介

Laravel millipackage that hides variables from getting dumped in the Whoops page when your app crashes.

README 文档

README

Even though Laravel >=6.x includes Ignition which no longer dumps your variables, it requires Whoops itself. And in some cases you can still get to the old error page with variables dumped.

This package works fine with Laravel 8. I haven't updated it lately because it just works as fine as it did before.

Laravel millipackage that hides your variables from getting dumped in the Whoops page when your app crashes.

Hidevara is japonese for hide the damn vars.

Usage

Install it:

$ composer require glaivepro/hidevara

To deal with the cases where the app crashes before loading providers, you should open your bootstrap/app.php and extend the handler. Find these rows (or something similar with another namespace if you've changed that):

// This is already there
$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

Immediately after that insert these lines to extend the handler:

// Enable only outside testing as this does not work well with phpunit... see below
if ('testing' != env('APP_ENV'))  // this will work even with config caching
	$app->extend(
		Illuminate\Contracts\Debug\ExceptionHandler::class,
		function($handler) {
			return new GlaivePro\Hidevara\HidingHandler($handler);
	});

By default this package will:

  • leave your GET and FILES intact;
  • hide value of any POST field that has a name containing password;
  • hide values of SESSION and COOKIE;
  • remove almost all SERVER variables (except REDIRECT_STATUS, REQUEST_METHOD, QUERY_STRING, REQUEST_URI);
  • remove all ENV variables.

"Hide" means that the value will be replaced with a string. By default it's empty string for null/emptystring values and [hidden] for everything else.

Customization

Publish the config:

$ php artisan vendor:publish --provider="GlaivePro\Hidevara\Provider"

Now you've got your very own config/hidevara.php file to edit.

You'll see a set of rules ('action' => $test) associated with each of the variables. The test can be an array of exact field names, string with a regex or true to take this action for anything.

Here's an example:

	'_GET' => [                   //this is the ruleset for fields in GET
		'expose' => true,         // show all fields
	],

	'_ENV' => [
		'remove' => ['APP_KEY'],  // remove key field entirely
		'hide' => '/password/i',  // hide anything that matches regex contains password
		'trash' => '/PUSHER/'     // anything that's not 'expose' or 'hide' will remove matched fields
		'expose' => true,         // expose all that remains
	],
	
	'_SERVER' => [
		'expose' => ['REQUEST_METHOD'],  // show the REQUEST_METHOD
		                                 // everything that hasn't matched a rule will be removed
	],

There are also replaceHiddenValueWith and replaceHiddenEmptyValueWith where you can supply whatever strings you love (like 🍑).

Changes to error handling

To hide the global variables from Whoops, they are hijacked/ruined just before calling your Handler::render(). If you need access to the original global at that method, you can get them in $GLOBALS['hidevara']. For example, $GLOBALS['hidevara']['_SERVER'] is what $_SERVER was.

Working with PHPUnit

Sometimes (supposedly when an exception is raised) this package crashes PHPUnit. To prevent this, we are not enabling the custom handling when the environment is testing.

If you do need to enable this while running PHPUnit, the errors can be prevented by setting processIsolation="true" on the <phpunit> tag in your phpunit.xml.

Collaboration

Pls help! Here are the open problems and questions:

  • We should make a console command that fixes app\bootstrap.php. Can we force calling it in the provider if needed?
  • What should the default config be?
  • Should config allow repeating the same type of rule? It's possible but would make config syntax more complicated.
  • Are there better ways to do this in Laravel?
  • Can we intercept directly in the Whoopsies PrettyPageHandler and make this not Laravel specific?

Change log

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

glaivepro/hidevara 适用场景与选型建议

glaivepro/hidevara 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 307.82k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2018 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「laravel」 「whoops」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 glaivepro/hidevara 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 glaivepro/hidevara 我们能提供哪些服务?
定制开发 / 二次开发

基于 glaivepro/hidevara 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 307.82k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 35
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 27
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-06