Bearer
A bearer is a type of authentication token that a user or system presents to verify its identity. Bearer tokens are commonly used in web applications, APIs, and network protocols. The term bearer means that anyone who possesses the token is considered authenticated, without requiring additional verification. Bearer tokens are simple to implement but require strong protection. Since possession of the token alone grants access, unauthorized individuals who get the token can use it as if they were the legitimate user.
Configurations
The bearer mechanism has the following configurations:
Configuration
Description
Bearer Token
The token string represents the user's authentication and authorization claims.
Add the token as part of the Query parameter
You can include a bearer token as a query parameter in an HTTP request. This approach is generally discouraged because passing tokens in the URL exposes them in browser history, logs, caches, and monitoring systems, increasing the risk of unauthorized access. Using the Authorization header is a much safer and recommended method for transmitting bearer tokens.
If you still need to pass the token as a query parameter, you can append it to the URL as shown below:
Add the token as part of the Header (Recommended)
Adding a bearer token in the request header is the recommended and standard practice for bearer token authentication in HTTP requests. You can include the token in the Authorization header, as shown below:
Add the token as part of the Cookie
Bearer tokens are usually not stored in cookies because doing so introduces security risks. Storing authentication tokens in cookies can make them vulnerable to attacks, such as cross-site scripting (XSS) and cross-site request forgery (CSRF). The recommended and more secure approach is to send bearer tokens in the Authorization header.
If you still wish to store a bearer token in a cookie, you can set the cookie using server-side code.
Example
The following are some samples that you can use to configure the Bearer mechanism in the Advanced mode:
Sample 1
def bearer_token_hook(scanctx: ScanContext, pluginctx: PluginContext, testcase: TestCase, **kwargs) -> list[Assertion]:
attributes = testcase.get_attributes()
bearer_token = "bearer_token"
set_key = "token_identifier_key"
bearer_format = "bearer_format_template"
bearer_value = bearer_format.replace("{{value}}", str(bearer_token))
auth_attr = ""
# set user
normal_user = True
bola_user = False
set_header = True
set_cookie = False
set_query = False
# set api key in header
if set_header:
attributes.set("mutated.auth.attribute", "mutated.http.request.header.%s" % set_key)
auth_attr = "mutated.http.request.header.%s" % set_key
# set api key in query
if set_query:
attributes.set("mutated.auth.attribute", "mutated.http.request.query.param.%s" % set_key)
auth_attr = "mutated.http.request.query.param.%s" % set_key
# set api key in cookie
if set_cookie:
attributes.set("mutated.auth.attribute", "mutated.http.request.cookie.%s" % set_key)
auth_attr = "mutated.http.request.cookie.%s" % set_key
if normal_user:
attributes.set("mutated.role.user", bearer_value)
attributes.set(auth_attr, bearer_value)
if bola_user:
attributes.set("mutated.role.bolauser", bearer_value)
return []Sample 2
Sample 3
Last updated
Was this helpful?