Skip to content

Ignoring domains #11

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

Merged
merged 9 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ For example:
],
```

#### ☑️ Ignore Domains

If for any reason you wish to disable StageFront on specific doamins, you can add these to the `ignore_udomains` array in the [configuration file](#-publish-configuration-file). You can't set this in the `.env` file.

For example:

```php
'ignore_domains' => [
'admin.domain.com',
],
```

#### ☑️ Link Live Site

If you set the URL to your live site, a link will be shown underneath the login form.
Expand Down
10 changes: 10 additions & 0 deletions config/stagefront.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,14 @@
*/
'ignore_urls' => [],


/**
* The following domains will be ignored by StageFront.
* Access to these domains will never be blocked.
* Default: []
* Example: 'admin.domain.com'
*/
'ignore_domains' => [
],

];
9 changes: 9 additions & 0 deletions src/Shield.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected function isActive()
*/
protected function currentUrlIsIgnored()
{
$ignoredDomains = Config::get('stagefront.ignore_domains', []);
$ignoredUrls = Config::get('stagefront.ignore_urls', []);
$ignoredUrls[] = Config::get('stagefront.url');

Expand All @@ -66,6 +67,14 @@ protected function currentUrlIsIgnored()
}
}

foreach ($ignoredDomains as $url) {
$url = trim($url, '/');

if (str_contains(Request::url(), $url)) {
return true;
}
}

return false;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/StageFrontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,20 @@ public function urls_can_be_ignored_so_access_is_not_denied_by_stagefront()
$this->get('/public/route')->assertStatus(200)->assertSee('Route');
}

/** @test */
public function domains_can_be_ignored_so_access_is_not_denied_by_stagefront()
{
$this->url = Config::get('stagefront.url');

$this->registerRouteWithDomain('/admin', 'Admin');

Config::set('stagefront.ignore_domains', ['domain.example.com']);

$this->enableStageFront();

$this->call('GET', 'http://domain.example.com/admin')->assertStatus(200)->assertSee('Admin');
}

/** @test */
public function ignored_urls_can_be_accessed_by_non_whitelisted_ips()
{
Expand Down Expand Up @@ -486,4 +500,19 @@ protected function registerRoute($url, $text)
return $text;
})->middleware(Config::get('stagefront.middleware'));
}

/**
* Register a test route.
*
* @param string $url
* @param string $text
*/
protected function registerRouteWithDomain($url, $text)
{
Route::domain('domain.example.com')->group(function () use ($url, $text) {
Route::get($url, function () use ($text) {
return $text;
})->middleware(Config::get('stagefront.middleware'));
});
}
}
Loading