Sec Link
Protect links in your domain with a token
Last updated
Protect links in your domain with a token
Last updated
Asians Cloud CDN has Sec Link feature which can protect certain links of your domain with auto expiring token.
This token can be generated automatically by our CDN if Sec Redirect feature is enabled. Otherwise, you can generate the token in your application, we have put code samples.
The following configurations are needed for the setting to work properly.
Enable Sec Redirect: If Sec Redirect feature is enabled, then the
Protected paths: The list of paths that will be protected with token.
API Secret: A secret string that is used in the token to prevent forgery.
Expire Seconds: The number of seconds each token should be valid for.
Sleep Seconds: The number of seconds the plugin should sleep to make the visitor wait before redirecting them when Enable Sec Redirect is enabled. Note: Sleep Seconds should always be less than Expire Seconds.
The Sec Redirection inside Sec Link is used for automatically generating the token and redirecting the user.
To use it, we have to add /sec/
in front of the URL.
So if our original link is https://www.example.com/some-url/
then it will become https://www.example.com/sec/some-url/
When the user visit the new url (https://www.example.com/sec/some-url
), they will wait for some time (sleep seconds) and they will be redirected to the original link with the security parameters. For Example, https://www.example.com/some-url?md5=NH1XQCFoTWszY1xGZ01wRg&expires=1669140298
The md5
query parameter contains the token
The expires
parameter contains the timestamp of when the link will expire.
We can use this tool to convert the timestamp to date.
1. Protect download link with an auto expiring link: When you have an apk download link and you want to protect it with an redirecting and auto expiring link to avoid CC attack which leads huge traffics, you can use this setting:
Enable Sec Redirect: True
Protected paths: e.g. /download The dictionary of paths to protect. The key is the path to protect, the value is the path to redirect to. For example, if you want to protect /download/1.apk, you can set it to or /download/1.apk.
API Secret: e.g. 6f0e2f08cc80f45ad3004e16af1e2cd6 . A string that is used in the token to prevent forgery. It should be a secret string that only you know.
Expire Seconds: 1200 The number of seconds each token should be valid for. Do not set it too small when you have a big file to download.
Sleep Seconds: 2. The number of seconds to sleep before returning the redirect. This is to prevent the token from being used in a DOS attack.
Then you can add /sec/ as the prefix of all your protected url path, e.g. /download/1.apk will be /sec/download/1.apk. The original download link will be protected with sec parameters and directly access is invalid.
2. Protect API with an auto expiring link: When you have an API and you want to protect it with an auto expiring link to avoid CC attack which leads huge traffics, you can use this setting.
Enable Sec Redirect: False
Protected paths: e.g. /api/hello The dictionary of paths to protect. The key is the path to protect, the value is the path to redirect to. For example, if you want to protect /api/hello, you can set it to /api/hello
API Secret: e.g. 6f0e2f08cc80f45ad3004e16af1e2cd6. A string that is used in the token to prevent forgery. It should be a secret string that only you know.
Expire Seconds: 60. The number of seconds each token should be valid for.
Sleep Seconds: 2. Any number because it is not used in this scenario.
Then you need to add validation parameters into you url. e.g, /api/hello will be /api/hello?md5=xxx&expires=xxx . The original api link will be protected with sec parameters and directly access is invalid.
Calculate the expiry time by adding Expire Seconds to the current epoch time
Concatenate X = Expiry Time + the URL path to be protected + Expire Seconds + the IP address of the requestor + " " + API Secret
Take the binary form of the MD5 of X
Encode the binary form as base64
Replace "+" with "-", "/" with "_" and strip all "=" to make it URL friendly
Bash
Python
Go
PHP