A Cloud-Native Security Monitoring and Protection for Modern Applications
Documentation | Quick Start | Blog | Chat with us on Slack!
SecureNative performs user monitoring by analyzing user interactions with your application and various factors such as network, devices, locations and access patterns to stop and prevent account takeover attacks.
When using Composer run the following command:
$ composer require securenative/securenative-php
require_once __DIR__ . '/vendor/autoload.php';
use SecureNative\sdk\SecureNative;
use SecureNative\sdk\SecureNativeOptions;
use SecureNative\sdk\EventTypes;
use SecureNative\sdk\SecureNativeContext;
To get your API KEY, login to your SecureNative account and go to project settings page:
$options = new SecureNativeOptions();
$options->setTimeout(100)
->setApiUrl("API URL")
->setDisable(false)
->setInterval(100)
->setAutoSend(true)
->setMaxEvents(10)
->setLogLevel('fatal');
// Passing `$options` is optional, will use default params
SecureNative::init("[API_KEY]", $options);
Attach securenative.json
file to your root folder:
{
"SECURENATIVE_API_KEY": "YOUR_API_KEY",
"SECURENATIVE_APP_NAME": "APP_NAME",
"SECURENATIVE_API_URL": "API_URL",
"SECURENATIVE_INTERVAL": 1000,
"SECURENATIVE_MAX_EVENTS": 100,
"SECURENATIVE_TIMEOUT": 1500,
"SECURENATIVE_AUTO_SEND": true,
"SECURENATIVE_DISABLE": false,
"SECURENATIVE_LOG_LEVEL": "fatal"
}
Then, call SDK's init
function without props (sending props will override JSON configurations).
SecureNative::init();
Pass desired environment variables (for example):
SECURENATIVE_API_KEY=TEST_KEY
SECURENATIVE_API_URL=http://url
SECURENATIVE_INTERVAL=100
SECURENATIVE_MAX_EVENTS=30
SECURENATIVE_TIMEOUT=1500
SECURENATIVE_AUTO_SEND=true
SECURENATIVE_DISABLE=false
SECURENATIVE_LOG_LEVEL=fatal
Then, call SDK's init
function without props (sending props will override JSON configurations).
SecureNative::init();
Once the SDK has been initialized, tracking requests sent through the SDK instance.
$clientToken = "[SECURED_CLIENT_TOKEN]";
$headers = (object)["user-agent" => "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us"];
$ip = "79.179.88.157";
$remoteIp = null;
$url = null;
$method = null;
$body = null;
$ctx = new SecureNativeContext($clientToken, $ip, $remoteIp, $headers, $url, $method, $body);
SecureNative::track(array(
'event' => EventTypes::LOG_IN,
'context' => $ctx,
'userId' => '1234',
'userTraits' => (object)[
'name' => 'Your Name',
'email' => 'name@gmail.com'
],
// Custom properties
'properties' => (object)[
"custom_param1" => "CUSTOM_PARAM_VALUE",
"custom_param2" => true,
"custom_param3" => 3
]
));
You can also create request context from request:
SecureNative::track(array(
'event' => EventTypes::LOG_IN,
'context' => SecureNative::contextFromContext(),
'userId' => '1234',
'userTraits' => (object)[
'name' => 'Your Name',
'email' => 'name@gmail.com'
],
// Custom properties
'properties' => (object)[
"custom_param1" => "CUSTOM_PARAM_VALUE",
"custom_param2" => true,
"custom_param3" => 3
]
));
Example
$options = new SecureNativeOptions();
$ver = SecureNative::verify(array(
'event' => EventTypes::VERIFY,
'userId' => '1234',
'context' => SecureNative::fromRequest(),
'userTraits' => (object)[
'name' => 'Your Name',
'email' => 'name@gmail.com'
]
));
print_r($ver->riskLevel); // (Low, Medium, High)
print_r($ver->score); // (0 - Very Low, 1 - Very High)
print_r($ver->triggers); // (Example: ["TOR", "New IP", "New City"])
Apply our filter to verify the request is from us, for example:
$verified = SecureNative::getMiddleware()->verifySignature();
if ($verified) {
// Request is trusted (coming from SecureNative)
}
You can specify custom header keys to allow extraction of client ip from different providers. This example demonstrates the usage of proxy headers for ip extraction from Cloudflare.
{
"SECURENATIVE_API_KEY": "YOUR_API_KEY",
"SECURENATIVE_PROXY_HEADERS": ["CF-Connecting-IP"]
}
Initialize sdk as shown above.
$options = new SecureNativeOptions();
$options->setProxyHeaders(["CF-Connecting-IP"]);
SecureNative::init();
By default, SecureNative SDK remove any known pii headers from the received request. We also support using custom pii headers and regex matching via configuration, for example:
{
"SECURENATIVE_API_KEY": "YOUR_API_KEY",
"SECURENATIVE_PII_HEADERS": ["apiKey"]
}
Initialize sdk as shown above.
$options = new SecureNativeOptions();
$options->setPiiRegexPattern("/http_auth_/i");
SecureNative::init();