I have a Laravel 5 project that is using the bepsvpt/secure-headers package with the following config file:
config/secure-headers.php
<?php
return [
'x-content-type-options' => 'nosniff',
'x-download-options' => 'noopen',
'x-frame-options' => 'sameorigin',
'x-permitted-cross-domain-policies' => 'none',
'x-xss-protection' => '1; mode=block',
/*
* Referrer-Policy
*
* Reference: https://w3c.github.io/webappsec-referrer-policy
*
* Available Value: 'no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin',
* 'same-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url'
*/
'referrer-policy' => 'strict-origin-when-cross-origin',
'hsts' => [
'enable' => env('SECURITY_HEADER_HSTS_ENABLE', false),
'max-age' => 15552000,
'include-sub-domains' => false,
],
/*
* Content Security Policy
*
* Reference: https://developer.mozilla.org/en-US/docs/Web/Security/CSP
*
* csp will be ignored if custom-csp is not null.
*
* Note: custom-csp does not support report-only.
*/
'custom-csp' => env('SECURITY_HEADER_CUSTOM_CSP', null),
'csp' => [
'report-only' => false,
'report-uri' => env('CONTENT_SECURITY_POLICY_REPORT_URI', false),,
'upgrade-insecure-requests' => false,
'base-uri' => [
//
],
'default-src' => [
//
],
'child-src' => [
//
],
'script-src' => [
'allow' => [
//
],
'hashes' => [
// ['sha256' => 'hash-value'],
],
'nonces' => [
//
],
'self' => false,
'unsafe-inline' => false,
'unsafe-eval' => false,
],
'style-src' => [
'allow' => [
//
],
'self' => false,
'unsafe-inline' => false,
],
'img-src' => [
'allow' => [
//
],
'types' => [
//
],
'self' => false,
'data' => false,
],
/*
* The following directives are all use 'allow' and 'self' flag.
*
* Note: default value of 'self' flag is false.
*/
'font-src' => [
//
],
'connect-src' => [
//
],
'form-action' => [
//
],
'frame-ancestors' => [
//
],
'media-src' => [
//
],
'object-src' => [
//
],
/*
* plugin-types only support 'allow'.
*/
'plugin-types' => [
//
],
],
];
When I try to run the application (web request or php artisan), I get the following error:
PHP Fatal error: Cannot use empty array elements in arrays in C:\Web\myapp\config\secure-headers.php on line 4
Of course, line 4 of the file looks totally fine!
What is the issue here?
This error, which is not documented anywhere I can find online, comes from having two commas in a row with nothing between them inside the array.
In my case, this actually appeared on line 42 of the file, not line 4 as indicated by the error message, which sounds like a bug in the compiler which identifies the first item in the array instead of the actual location of the "empty array element".
NOTE: In PHP 7.2.15+, 7.3.2+, and 7.4.0+, the error message has been changed to report the line number of the previous valid element instead of the line number of the beginning of the array. While this may still be off by one or more lines, it is usually close enough to the problem to make it much easier to find.
I got the same error, while pointing at line 2, the error was on line 6.
I spent hours troubleshooting helplessly because it was a familiar code and I didn't know when an extra , got at the back of 'available' => $faker->boolean(85),
return [
'id' => $id,
'user_id' => $id,
'slug' => $slug,
'speciality' => $faker->randomElement(['Option A','Optoin B']),
'available' => $faker->boolean(85),,
'subscription_ends_at' => $faker->dateTimeBetween('-5 day', '30 day'),
'verified_at' => $faker->dateTimeBetween('-50 day', '-16 minute'),
];
Simply search your code for ,, or spaces between two commas , , on the same line as pointed out by #Moshe Katz.
This thread is a life saver.
I got this error and yes, the line indicated as where the error happened was wrong(Error was on line 10 instead of line 2 of the code below):
return Http::response(
["popularity" => 113.485,
"vote_count" => 9016,
"video" => false,
"poster_path" => "/qa6HCwP4Z15l3hpsASz3auugEW6.jpg",
"id" => 920,
"adult" => false,
"backdrop_path" => "/8KeWhoMpqbzZRyHPkTtWSLWkL5L.jpg",
"original_language" => "en",
"original_title" => "Cars",
"genre_ids" => [,
0 => 12,
1 => 16,
2 => 35,
3 => 10751,
],
"title" => "Cars",
"vote_average" => 6.8,
"overview" => "Lightning McQueen, a hotshot rookie race car driven to succeed, discovers that life is about the journey, not the finish line, when he finds himself unexpectedly detoured in the sleepy Route 66 town of Radiator Springs. On route across the country to the big Piston Cup Championship in California to compete against two seasoned pros, McQueen gets to know the town's offbeat characters.",
"release_date" => "2006-06-08",
]);
The issue was from a typo where I added a comma after the square bracket resulting in "[,"
So if you try the suggestions above and it doesn't work, look for a "[," and remove the trailing comma.
Related
I have a Laravel 5 project that is using the bepsvpt/secure-headers package with the following config file:
config/secure-headers.php
<?php
return [
'x-content-type-options' => 'nosniff',
'x-download-options' => 'noopen',
'x-frame-options' => 'sameorigin',
'x-permitted-cross-domain-policies' => 'none',
'x-xss-protection' => '1; mode=block',
/*
* Referrer-Policy
*
* Reference: https://w3c.github.io/webappsec-referrer-policy
*
* Available Value: 'no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin',
* 'same-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url'
*/
'referrer-policy' => 'strict-origin-when-cross-origin',
'hsts' => [
'enable' => env('SECURITY_HEADER_HSTS_ENABLE', false),
'max-age' => 15552000,
'include-sub-domains' => false,
],
/*
* Content Security Policy
*
* Reference: https://developer.mozilla.org/en-US/docs/Web/Security/CSP
*
* csp will be ignored if custom-csp is not null.
*
* Note: custom-csp does not support report-only.
*/
'custom-csp' => env('SECURITY_HEADER_CUSTOM_CSP', null),
'csp' => [
'report-only' => false,
'report-uri' => env('CONTENT_SECURITY_POLICY_REPORT_URI', false),,
'upgrade-insecure-requests' => false,
'base-uri' => [
//
],
'default-src' => [
//
],
'child-src' => [
//
],
'script-src' => [
'allow' => [
//
],
'hashes' => [
// ['sha256' => 'hash-value'],
],
'nonces' => [
//
],
'self' => false,
'unsafe-inline' => false,
'unsafe-eval' => false,
],
'style-src' => [
'allow' => [
//
],
'self' => false,
'unsafe-inline' => false,
],
'img-src' => [
'allow' => [
//
],
'types' => [
//
],
'self' => false,
'data' => false,
],
/*
* The following directives are all use 'allow' and 'self' flag.
*
* Note: default value of 'self' flag is false.
*/
'font-src' => [
//
],
'connect-src' => [
//
],
'form-action' => [
//
],
'frame-ancestors' => [
//
],
'media-src' => [
//
],
'object-src' => [
//
],
/*
* plugin-types only support 'allow'.
*/
'plugin-types' => [
//
],
],
];
When I try to run the application (web request or php artisan), I get the following error:
PHP Fatal error: Cannot use empty array elements in arrays in C:\Web\myapp\config\secure-headers.php on line 4
Of course, line 4 of the file looks totally fine!
What is the issue here?
This error, which is not documented anywhere I can find online, comes from having two commas in a row with nothing between them inside the array.
In my case, this actually appeared on line 42 of the file, not line 4 as indicated by the error message, which sounds like a bug in the compiler which identifies the first item in the array instead of the actual location of the "empty array element".
NOTE: In PHP 7.2.15+, 7.3.2+, and 7.4.0+, the error message has been changed to report the line number of the previous valid element instead of the line number of the beginning of the array. While this may still be off by one or more lines, it is usually close enough to the problem to make it much easier to find.
I got the same error, while pointing at line 2, the error was on line 6.
I spent hours troubleshooting helplessly because it was a familiar code and I didn't know when an extra , got at the back of 'available' => $faker->boolean(85),
return [
'id' => $id,
'user_id' => $id,
'slug' => $slug,
'speciality' => $faker->randomElement(['Option A','Optoin B']),
'available' => $faker->boolean(85),,
'subscription_ends_at' => $faker->dateTimeBetween('-5 day', '30 day'),
'verified_at' => $faker->dateTimeBetween('-50 day', '-16 minute'),
];
Simply search your code for ,, or spaces between two commas , , on the same line as pointed out by #Moshe Katz.
This thread is a life saver.
I got this error and yes, the line indicated as where the error happened was wrong(Error was on line 10 instead of line 2 of the code below):
return Http::response(
["popularity" => 113.485,
"vote_count" => 9016,
"video" => false,
"poster_path" => "/qa6HCwP4Z15l3hpsASz3auugEW6.jpg",
"id" => 920,
"adult" => false,
"backdrop_path" => "/8KeWhoMpqbzZRyHPkTtWSLWkL5L.jpg",
"original_language" => "en",
"original_title" => "Cars",
"genre_ids" => [,
0 => 12,
1 => 16,
2 => 35,
3 => 10751,
],
"title" => "Cars",
"vote_average" => 6.8,
"overview" => "Lightning McQueen, a hotshot rookie race car driven to succeed, discovers that life is about the journey, not the finish line, when he finds himself unexpectedly detoured in the sleepy Route 66 town of Radiator Springs. On route across the country to the big Piston Cup Championship in California to compete against two seasoned pros, McQueen gets to know the town's offbeat characters.",
"release_date" => "2006-06-08",
]);
The issue was from a typo where I added a comma after the square bracket resulting in "[,"
So if you try the suggestions above and it doesn't work, look for a "[," and remove the trailing comma.
For the currency conversion i am using "florianv/laravel-swap": "^1.1" library. Florianv/Laravel-swap.
As Fixer.io has changed its implementation, it is necessary to pass the access_key with the request, and because of that i am getting this error: "InvalidArgumentException: The "access_key" option must be provided to use fixer.io in /var/www/project/project-files/vendor/florianv/exchanger/src/Service/Fixer.php:51".
I registered and got the access_key.
I updated the library using composer and now i can see three constants in the vendor/florianv/exchanger/src/Service/Fixer.php.
const ACCESS_KEY_OPTION = 'access_key';
const LATEST_URL = 'http://data.fixer.io/api/latest?base=%s&access_key=%s';
const HISTORICAL_URL = 'http://data.fixer.io/api/%s?base=%s&access_key=%s';
To pass the access key i tried this:
I have a swap.php in config folder which looks something like this:
return [
'options' => [
'cache_ttl' => 86400, // 24 hours.
'cache_key_prefix' => 'currency_rate'
],
'services' => [
'fixer' => true,
],
'currency_layer' => [
'access_key' => 'asdfas7832mw3nsdfa776as8dfa', // Your app id
'enterprise' => true, // True if your AppId is an enterprise one
],
'cache' => env('CACHE_DRIVER', 'file'),
'http_client' => null,
'request_factory' => null,
'cache_item_pool' => null,
];
This had one more option which was commented, i enabled and passed the access_key in it but it doesn't work.
I also added it in services block below 'fixer => true'.
'currency_layer' => [
'access_key' => 'asdfas7832mw3nsdfa776as8dfa'
]
Also in options block:
'options' => [
'cache_ttl' => 86400, // 24 hours.
'cache_key_prefix' => 'currency_rate',
'access_key'=>'7ca208e9136c5e140d6a14427bf9ed21'
],
I tried with adding access_key in config/services.php file but it also didn't work.
'fixer' => [
'access_key' => 'asdfas7832mw3nsdfa776as8dfa'
],
Even i tried, adding to env file and calling from there, but no success. How do i pass the access_key, can anyone help me on this, what should be the approach.
vendor/florianv/exchanger/src/Service/Fixer.php -> don't touch the constant (that was my own error).
Pass the options-array by creating the Builder:
$options = ['access_key' => 'YourGeneratedAPIKeyAtCurrencyLayer'];
$this->exchangeSwap = (new Builder($options))
->add('fixer', $options )
->build();
I hope I could help ;-)
I have a Laravel 5 project that is using the bepsvpt/secure-headers package with the following config file:
config/secure-headers.php
<?php
return [
'x-content-type-options' => 'nosniff',
'x-download-options' => 'noopen',
'x-frame-options' => 'sameorigin',
'x-permitted-cross-domain-policies' => 'none',
'x-xss-protection' => '1; mode=block',
/*
* Referrer-Policy
*
* Reference: https://w3c.github.io/webappsec-referrer-policy
*
* Available Value: 'no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin',
* 'same-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url'
*/
'referrer-policy' => 'strict-origin-when-cross-origin',
'hsts' => [
'enable' => env('SECURITY_HEADER_HSTS_ENABLE', false),
'max-age' => 15552000,
'include-sub-domains' => false,
],
/*
* Content Security Policy
*
* Reference: https://developer.mozilla.org/en-US/docs/Web/Security/CSP
*
* csp will be ignored if custom-csp is not null.
*
* Note: custom-csp does not support report-only.
*/
'custom-csp' => env('SECURITY_HEADER_CUSTOM_CSP', null),
'csp' => [
'report-only' => false,
'report-uri' => env('CONTENT_SECURITY_POLICY_REPORT_URI', false),,
'upgrade-insecure-requests' => false,
'base-uri' => [
//
],
'default-src' => [
//
],
'child-src' => [
//
],
'script-src' => [
'allow' => [
//
],
'hashes' => [
// ['sha256' => 'hash-value'],
],
'nonces' => [
//
],
'self' => false,
'unsafe-inline' => false,
'unsafe-eval' => false,
],
'style-src' => [
'allow' => [
//
],
'self' => false,
'unsafe-inline' => false,
],
'img-src' => [
'allow' => [
//
],
'types' => [
//
],
'self' => false,
'data' => false,
],
/*
* The following directives are all use 'allow' and 'self' flag.
*
* Note: default value of 'self' flag is false.
*/
'font-src' => [
//
],
'connect-src' => [
//
],
'form-action' => [
//
],
'frame-ancestors' => [
//
],
'media-src' => [
//
],
'object-src' => [
//
],
/*
* plugin-types only support 'allow'.
*/
'plugin-types' => [
//
],
],
];
When I try to run the application (web request or php artisan), I get the following error:
PHP Fatal error: Cannot use empty array elements in arrays in C:\Web\myapp\config\secure-headers.php on line 4
Of course, line 4 of the file looks totally fine!
What is the issue here?
This error, which is not documented anywhere I can find online, comes from having two commas in a row with nothing between them inside the array.
In my case, this actually appeared on line 42 of the file, not line 4 as indicated by the error message, which sounds like a bug in the compiler which identifies the first item in the array instead of the actual location of the "empty array element".
NOTE: In PHP 7.2.15+, 7.3.2+, and 7.4.0+, the error message has been changed to report the line number of the previous valid element instead of the line number of the beginning of the array. While this may still be off by one or more lines, it is usually close enough to the problem to make it much easier to find.
I got the same error, while pointing at line 2, the error was on line 6.
I spent hours troubleshooting helplessly because it was a familiar code and I didn't know when an extra , got at the back of 'available' => $faker->boolean(85),
return [
'id' => $id,
'user_id' => $id,
'slug' => $slug,
'speciality' => $faker->randomElement(['Option A','Optoin B']),
'available' => $faker->boolean(85),,
'subscription_ends_at' => $faker->dateTimeBetween('-5 day', '30 day'),
'verified_at' => $faker->dateTimeBetween('-50 day', '-16 minute'),
];
Simply search your code for ,, or spaces between two commas , , on the same line as pointed out by #Moshe Katz.
This thread is a life saver.
I got this error and yes, the line indicated as where the error happened was wrong(Error was on line 10 instead of line 2 of the code below):
return Http::response(
["popularity" => 113.485,
"vote_count" => 9016,
"video" => false,
"poster_path" => "/qa6HCwP4Z15l3hpsASz3auugEW6.jpg",
"id" => 920,
"adult" => false,
"backdrop_path" => "/8KeWhoMpqbzZRyHPkTtWSLWkL5L.jpg",
"original_language" => "en",
"original_title" => "Cars",
"genre_ids" => [,
0 => 12,
1 => 16,
2 => 35,
3 => 10751,
],
"title" => "Cars",
"vote_average" => 6.8,
"overview" => "Lightning McQueen, a hotshot rookie race car driven to succeed, discovers that life is about the journey, not the finish line, when he finds himself unexpectedly detoured in the sleepy Route 66 town of Radiator Springs. On route across the country to the big Piston Cup Championship in California to compete against two seasoned pros, McQueen gets to know the town's offbeat characters.",
"release_date" => "2006-06-08",
]);
The issue was from a typo where I added a comma after the square bracket resulting in "[,"
So if you try the suggestions above and it doesn't work, look for a "[," and remove the trailing comma.
I tried TNTSearch, but the results are only for the complete words. For example, the phrase Facilis dolorem gives me all combinations of records with the word facilis or word dolorem.
How can I do to the search with TNTSearch in Laravel?
LIKE %lore%
If I type lore, I don't get the records that have the word lore in the middle.
You should enable fuzzy search via config like mentioned in the docs:
'tntsearch' => [
'storage' => storage_path(), //place where the index files will be stored
'fuzziness' => env('TNTSEARCH_FUZZINESS', false),
'fuzzy' => [
'prefix_length' => 2,
'max_expansions' => 50,
'distance' => 2
],
],
ie. if this is your config set you variable TNTSEARCH_FUZZINESS in .env to true and you should get the results you expect.
Also, if you already have indexes created which seems like you do you'll have to reindex the content in order for fuzzines to kick in...
mine same issue not solved and finally used other good alternate:
laravel-scout-mysql-driver
try it
but exactly answer for your question:
you must use *lore* in your query. more documentation for queries:
Boolean Full-Text Searches
I had this issue and solved it via add 'asYouType' => false, in config\scout.php.
my code is :
'tntsearch' => [
'storage' => storage_path(), //place where the index files will be stored
'fuzziness' => true,
'fuzzy' => [
'prefix_length' => 2,
'max_expansions' => 50,
'distance' => 2
],
'asYouType' => false,
],
I am using the Official PHP driver to connect to Elasticsearch(v 2.3), every when I index a new document it takes from 5sec to 60sec to be able to get it into my filter results. How can I cut down the delay time to zero?
Here is my index query
# Document Body
$data = [];
$data['time'] = $time;
$data['unique'] = 1;
$data['lastACtivity'] = $time;
$data['bucket'] = 20,
$data['permission'] = $this->_user->permission; # Extracts User Permission
$data['ipaddress'] = $this->_client->ipaddress(); # Extracts User IP Address
# Construct Index
$indexRequest = [
'index' => 'gorocket',
'type' => 'log',
'refresh' => true,
'body' => $data
];
# Indexing Document
$confirmation = $client->index( $indexRequest );
And here is my search filter query
# Query array
$query =[ 'query' => [
'filtered' => [
'filter' => [
'bool' => [
'must' =>[
[
'match' => [ 'unique' => 1 ]
],
[
'range' => [
'lastACtivity' => [
'gte' => $from,
'lte' => $to
],
'_cache' => false
]
]
],
'must_not' => [
[ 'match' => [ 'type' => 'share' ] ],
]
]
]
]
]
];
# Prepare filter parameters
$filterParams = [
'index' => 'gorocket',
'type' => 'log',
'size' => 20,
'query_cache' => false,
'body' => $query
];
$client->search($filterParams);
Thank you.
When you index a new document you can specify the refresh parameter in order to make the new document available immediately for your next search operation.
$params = [
'index' => 'my-index',
'type' => 'my-type',
'id' => 123,
'refresh' => true <--- add this
];
$response = $client->index($params);
The refresh parameter is also available on the bulk operation if you're using it.
Be aware, though, that refreshing too often can have negative impacts on performance.
There is a refresh option provided, which needs a value (in seconds) to refresh the index. For example, if you update something in index, it gets written in the index but not ready for reading until the index is refreshed.
Refresh can be set to true for refreshing the index as soon as any change happens. This needs to be very carefully thought, because many times, it downgrades your performance as its an overkill to refresh for each small operation, plus many bulk refreshes can make the index busy.
Tip: Use an elasticsearch plugin, such as kopf and see more such options like refresh rate, to configure.