Software security is not security software. Here we're concerned with topics like authentication, access control, confidentiality, cryptography, and privilege management.
apiVersion
2019-04-01 and later, Azure storage accounts require a secure connection to respond to requests, but the requirement can be disabled with the supportsHttpsTrafficOnly
property.
{
"name": "Storage1",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-02-01",
...
"properties": {
"supportsHttpsTrafficOnly": false
}
}
resource example 'Microsoft.ContainerService/managedClusters@2018-03-31' = {
...
properties: {
...
addonProfiles: {}
}
}
{
"name": "[split(parameters('aksResourceId'),'/')[8]]",
"type": "Microsoft.ContainerService/managedClusters",
"apiVersion": "2018-03-31",
"properties": {
"mode": "Incremental",
"id": "[parameters('aksResourceId')]",
}
}
targetScope = 'subscription'
resource example 'microsoft.insights/logprofiles@2016-03-01' = {
...
properties: {
...
categories: [ 'Write' ]
}
}
{
"name": "string",
"type": "microsoft.insights/logprofiles",
"apiVersion": "2016-03-01",
...
"properties": {
...
"categories": [
"Write"
],
...
}
}
targetScope = 'subscription'
param emailAddress string
param phoneNumber string
resource example 'Microsoft.Security/securityContacts@2020-01-01-preview' = {
...
properties: {
...
emails: emailAddress
phone: phoneNumber
alertNotifications: {
state: 'Off'
minimalSeverity: 'High'
}
}
}
{
"name": "Security Officer",
"type": "Microsoft.Security/securityContacts",
"apiVersion": "2020-01-01-preview",
"properties": {
"emails": "secofficer@example.com",
"phone": "1212131314",
"alertNotifications": {
"state": "Off",
"minimalSeverity": "High"
},
...
}
@secure()
param sqlLogin string
@secure()
param sqlLoginPass string
param location string = resourceGroup().location
resource sqlServer 'Microsoft.Sql/servers@2021-11-01-preview' = {
name: 'server name'
location: location
tags: {
displayName: 'server name'
}
properties: {
administratorLogin: sqlLogin
administratorLoginPassword: sqlLoginPass
version: '12.0'
publicNetworkAccess: 'Disabled'
}
}
{
"name": "ProdSQLServer",
"type": "Microsoft.Sql/servers",
"apiVersion": "2021-02-01-preview",
...
"properties": {
"collation": "SQL_Latin1_General_CP1_CI_AS",
...
"resources": []
}
...
}
LocalAuthentication
framework to authenticate the user which may not be sufficient for apps requiring heightened security controls.LocalAuthentication
framework or using Touch ID based access controls in the Keychain service.LocalAuthentication
approach has some characteristics that make it less suitable for high risk apps such as banking, medical, and insurance:LocalAuthentication
is defined outside of the device's Secure Enclave which implies that their APIs can be hooked and modified on jailbroken devices.LocalAuthentication
authenticates the user by evaluating the context policy which may only evaluate to true
or false
. This boolean evaluation implies that the application will not be able to know who is really being authenticated, it just knows that fingerprint that is registered with the device was used or not. In addition, fingerprints that could be registered in the future will also successfully evaluate to true
.LocalAuthentication
framework to perform user authentication:
...
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
NSString *reason = @"Please authenticate using the Touch ID sensor.";
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:reason
reply:^(BOOL success, NSError *error) {
if (success) {
// Fingerprint was authenticated
} else {
// Fingerprint could not be authenticated
}
}
];
...
LocalAuthentication
framework to authenticate the user which may not be sufficient for apps requiring heightened security controls.LocalAuthentication
framework or using Touch ID based access controls in the Keychain service.LocalAuthentication
approach has some characteristics that make it less suitable for high risk apps such as banking, medical, and insurance:LocalAuthentication
is defined outside of the device's Secure Enclave which implies that their APIs can be hooked and modified on jailbroken devices.LocalAuthentication
authenticates the user by evaluating the context policy which may only evaluate to true
or false
. This boolean evaluation implies that the application will not be able to know who is really being authenticated, it just knows that fingerprint that is registered with the device was used or not. In addition, fingerprints that could be registered in the future will also successfully evaluate to true
.LocalAuthentication
framework to perform user authentication:
...
let context:LAContext = LAContext();
var error:NSError?
let reason:String = "Please authenticate using the Touch ID sensor."
if (context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error)) {
context.evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reason, reply: { (success, error) -> Void in
if (success) {
// Fingerprint was authenticated
}
else {
// Fingerprint could not be authenticated
}
})
}
...
isSecure
parameter set to true
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, and the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.isSecure
parameter to true
.
...
Cookie cookie = new Cookie('emailCookie', emailCookie, path, maxAge, false, 'Strict');
...
isSecure
parameter, cookies sent during an HTTPS request are also sent during subsequent HTTP requests. Sniffing network traffic over unencrypted wireless connections is a trivial task for attackers, and sending cookies (especially those with session IDs) over HTTP can result in application compromise.Secure
flag set to true
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.Secure
property.
...
HttpCookie cookie = new HttpCookie("emailCookie", email);
Response.AppendCookie(cookie);
...
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Sniffing network traffic over unencrypted wireless connections is a trivial task for attackers, so sending cookies (especially those with session IDs) over HTTP can result in application compromise.Secure
flag to true
Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or session identifiers, or carries a CSRF token.Secure
flag.
cookie := http.Cookie{
Name: "emailCookie",
Value: email,
}
http.SetCookie(response, &cookie)
...
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Attackers can then compromise the cookie by sniffing the unencrypted network traffic, which is particularly easy over wireless networks.Secure
flag set to true
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.use-secure-cookie
attribute enables the remember-me
cookie to be sent over unencrypted transport.
<http auto-config="true">
...
<remember-me use-secure-cookie="false"/>
</http>
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Sniffing network traffic over unencrypted wireless connections is a trivial task for attackers, so sending cookies (especially those with session IDs) over HTTP can result in application compromise.Secure
flag set to true
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.Secure
property to true
.
res.cookie('important_cookie', info, {domain: 'secure.example.com', path: '/admin', httpOnly: true, secure: false});
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Sniffing network traffic over unencrypted wireless connections is a trivial task for attackers, so sending cookies (especially those with session IDs) over HTTP can result in application compromise.NSHTTPCookieSecure
flag set to TRUE
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.Secure
flag.
...
NSDictionary *cookieProperties = [NSDictionary dictionary];
...
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
...
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Sniffing network traffic over unencrypted wireless connections is a trivial task for attackers, so sending cookies (especially those with session IDs) over HTTP can result in application compromise.Secure
flag to true
Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.Secure
flag.
...
setcookie("emailCookie", $email, 0, "/", "www.example.com");
...
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Attackers can then compromise the cookie by sniffing the unencrypted network traffic, which is particularly easy over wireless networks.Secure
flag to True
Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or session identifiers, or carries a CSRF token.Secure
flag.
from django.http.response import HttpResponse
...
def view_method(request):
res = HttpResponse()
res.set_cookie("emailCookie", email)
return res
...
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Attackers can then compromise the cookie by sniffing the unencrypted network traffic, which is particularly easy over wireless networks.Secure
flag set to true
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.Secure
flag.
Ok(Html(command)).withCookies(Cookie("sessionID", sessionID, secure = false))
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Sniffing network traffic over unencrypted wireless connections is a trivial task for attackers, so sending cookies (especially those with session IDs) over HTTP can result in application compromise.NSHTTPCookieSecure
flag set to TRUE
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data or carries a session identifier.Secure
flag.
...
let properties = [
NSHTTPCookieDomain: "www.example.com",
NSHTTPCookiePath: "/service",
NSHTTPCookieName: "foo",
NSHTTPCookieValue: "bar"
]
let cookie : NSHTTPCookie? = NSHTTPCookie(properties:properties)
...
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Sniffing network traffic over unencrypted wireless connections is a trivial task for attackers, so sending cookies (especially those with session IDs) over HTTP can result in application compromise.CSRF_COOKIE_SECURE
property to True
or set it to False
.Secure
flag for each cookie. If the flag is set, the browser will only send the cookie over HTTPS. Sending cookies over an unencrypted channel can expose them to network sniffing attacks, so the secure flag helps keep a cookie's value confidential. This is especially important if the cookie contains private data, session identifiers, or carries a CSRF token.Secure
bit for CSRF cookies.
...
MIDDLEWARE = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'csp.middleware.CSPMiddleware',
'django.middleware.security.SecurityMiddleware',
...
)
...
Secure
flag, cookies sent during an HTTPS request will also be sent during subsequent HTTP requests. Attackers can then compromise the cookie by sniffing the unencrypted network traffic, which is particularly easy over wireless networks.HttpOnly
flag to true
.HttpOnly
cookie property to prevent client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without the HttpOnly
flag enabled, attackers have easier access to user cookies.HttpOnly
property.
HttpCookie cookie = new HttpCookie("emailCookie", email);
Response.AppendCookie(cookie);
HttpOnly
flag to true
.HttpOnly
cookie property that prevents client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without HttpOnly
enabled, attackers have easier access to user cookies.HttpOnly
property.
cookie := http.Cookie{
Name: "emailCookie",
Value: email,
}
...
HttpOnly
flag to true
.HttpOnly
cookie property to prevent client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without the HttpOnly
flag enabled, attackers have easier access to user cookies.HttpOnly
property.
javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie("emailCookie", email);
// Missing a call to: cookie.setHttpOnly(true);
HttpOnly
flag to true
.HttpOnly
cookie property to prevent client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without the HttpOnly
flag enabled, attackers have easier access to user cookies.httpOnly
property.
res.cookie('important_cookie', info, {domain: 'secure.example.com', path: '/admin'});
HttpOnly
flag to true
.HttpOnly
cookie property to prevent client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without the HttpOnly
flag enabled, attackers have easier access to user cookies.HttpOnly
property.
setcookie("emailCookie", $email, 0, "/", "www.example.com", TRUE); //Missing 7th parameter to set HttpOnly
HttpOnly
flag to True
.HttpOnly
cookie property that prevents client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without HttpOnly
enabled, attackers have easier access to user cookies.HttpOnly
property.
from django.http.response import HttpResponse
...
def view_method(request):
res = HttpResponse()
res.set_cookie("emailCookie", email)
return res
...
HttpOnly
flag to true
.HttpOnly
cookie property to prevent client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without the HttpOnly
flag enabled, attackers have easier access to user cookies.HttpOnly
property.
Ok(Html(command)).withCookies(Cookie("sessionID", sessionID, httpOnly = false))
HttpCookie.HttpOnly
property to true
.httpOnlyCookies
attribute is false, meaning that the cookie is accessible through a client-side script. This is an unnecessary cross-site scripting threat, resulting in stolen cookies. Stolen cookies can contain sensitive information identifying the user to the site, such as the ASP.NET session ID or forms authentication ticket, and can be replayed by the attacker in order to masquerade as the user or obtain sensitive information.
<configuration>
<system.web>
<httpCookies httpOnlyCookies="false">
HttpOnly
flag to true
for CSRF cookies.HttpOnly
cookie property that prevents client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without HttpOnly
enabled, attackers have easier access to user cookies.django.middleware.csrf.CsrfViewMiddleware
Django middleware, CSRF cookies are sent without setting the HttpOnly
property.
...
MIDDLEWARE = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'csp.middleware.CSPMiddleware',
'django.middleware.security.SecurityMiddleware',
...
)
...
HttpOnly
flag to true
.HttpOnly
cookie property to prevent client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without the HttpOnly
flag enabled, attackers have easier access to user cookies.HttpOnly
flag to true
.
server.servlet.session.cookie.http-only=false
HttpOnly
flag to true
.HttpOnly
cookie property to prevent client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without the HttpOnly
flag enabled, attackers have easier access to user cookies.HttpOnly
flag to true
.
session_set_cookie_params(0, "/", "www.example.com", true, false);
HttpOnly
flag to true
for session cookies.HttpOnly
cookie property that prevents client-side scripts from accessing the cookie. Cross-site scripting attacks often access cookies in an attempt to steal session identifiers or authentication tokens. Without HttpOnly
enabled, attackers have easier access to user cookies.HttpOnly
property.
...
MIDDLEWARE = (
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'csp.middleware.CSPMiddleware',
'django.middleware.security.SecurityMiddleware',
...
)
...
SESSION_COOKIE_HTTPONLY = False
...
__Host-
or __Secure-
prefix must have the Secure attribute set, must not set Domain attribute, and must restrict Path attribute value to /
.__Host-
and __Secure-
prefix must be set with the secure attribute. They must be set from a secure page (HTTPS). Additionally, a __Host-
prefixed cookie must not have a domain attribute specified (so that it is not sent to subdomains) and the path attribute must be set to /
. Violation of these rules can cause a browser to reject the cookie. Restricting a cookie's access to a secure channel protects it from being sent or being overwritten by a forged site over an unencrypted HTTP channel. Restrictions provided by the __Host
prefix prevent a cookie from being accessed by a subdomain where the subdomain might be owned by different entities such as a shared blog platform.SameSite
attribute on session cookies.SameSite
parameter limits the scope of the cookie so that it is only attached to a request if the request is generated from first-party or same-site context. This helps to protect cookies from Cross-Site Request Forgery (CSRF) attacks. The SameSite
parameter can have the following three values:Strict
, cookies are only sent along with requests upon top-level navigation.Lax
, cookies are sent with top-level navigation from the same host as well as GET requests originated to the host from third-party sites. For example, suppose a third-party site has either iframe
or href
tags that link to the host site. If a user follows the link, the request will include the cookie.SameSite
attribute to None
for session cookies.
...
Cookie cookie = new Cookie('name', 'Foo', path, -1, true, 'None');
...
SameSite
attribute on session cookies.SameSite
attribute limits the scope of the cookie such that it will only be attached to a request if the request is generated from first-party or same-site context. This helps to protect cookies from Cross-Site Request Forgery (CSRF) attacks. The SameSite
attribute can have the following three values:Strict
, cookies are only sent along with requests upon top-level navigation.Lax
, cookies are sent with top-level navigation from the same host as well as GET requests originating from third-party sites, including those that have either iframe
or href
tags that link to the host site. If a user follows the link, the request will include the cookie.SameSite
attribute for session cookies.
...
CookieOptions opt = new CookieOptions()
{
SameSite = SameSiteMode.None;
};
context.Response.Cookies.Append("name", "Foo", opt);
...
SameSite
attribute on session cookies.SameSite
attribute limits the scope of the cookie so that it is only attached to a request if the request is generated from first-party or same-site context. This helps to protect cookies from Cross-Site Request Forgery (CSRF) attacks. The SameSite
attribute can have the following three values:Strict
, cookies are only sent along with requests upon top-level navigation.Lax
, cookies are sent with top-level navigation from the same host as well as GET requests originated to the host from third-party sites. For example, suppose a third-party site has either iframe
or href
tags that link to the host site. If a user follows the link, the request will include the cookie.SameSite
attribute for session cookies.
c := &http.Cookie{
Name: "cookie",
Value: "samesite-none",
SameSite: http.SameSiteNoneMode,
}
SameSite
attribute on session cookies.SameSite
attribute limits the scope of the cookie so that it is only attached to a request if the request is generated from first-party or same-site context. This helps to protect cookies from Cross-Site Request Forgery (CSRF) attacks. The SameSite
attribute can have the following three values:Strict
, cookies are only sent along with requests upon top-level navigation.Lax
, cookies are sent with top-level navigation from the same host as well as GET requests originating from third-party sites, including those that have either iframe
or href
tags that link to the host site. For example, suppose there is a third-party site that has either iframe
or href
tags that link to the host site. If a user follows the link, the request will include the cookie.SameSite
attribute for session cookies.
ResponseCookie cookie = ResponseCookie.from("myCookie", "myCookieValue")
...
.sameSite("None")
...
SameSite
attribute on session cookies.SameSite
attribute limits the scope of the cookie so that it is only attached to a request if the request is generated from first-party or same-site context. This helps to protect cookies from Cross-Site Request Forgery (CSRF) attacks. The SameSite
attribute can have the following three values:Strict
, cookies are only sent along with requests upon top-level navigation.Lax
, cookies are sent with top-level navigation from the same host as well as GET requests originating from third-party sites, including those that have either iframe
or href
tags that link to the host site. For example, suppose there is a third-party site that has either iframe
or href
tags that link to the host site. If a user follows the link, the request will include the cookie.SameSite
attribute for session cookies.
app.get('/', function (req, res) {
...
res.cookie('name', 'Foo', { sameSite: false });
...
}
SameSite
attribute on session cookies.SameSite
attribute limits the scope of the cookie such that it will only be attached to a request if the request is generated from first-party or same-site context. This helps to protect cookies from Cross-Site Request Forgery (CSRF) attacks. The SameSite
attribute can have the following three values:Strict
, cookies are only sent along with requests upon top-level navigation.Lax
, cookies are sent with top-level navigation from the same host as well as GET requests originated to the host from third-party sites. For example, suppose a third-party site has either iframe
or href
tags that link to the host site. If a user follows the link, the request will include the cookie.SameSite
attribute for session cookies.
ini_set("session.cookie_samesite", "None");
SameSite
attribute on session cookies.samesite
parameter limits the scope of the cookie so that it is only attached to a request if the request is generated from first-party or same-site context. This helps to protect cookies from Cross-Site Request Forgery (CSRF) attacks. The samesite
parameter can have the following three values:Strict
, cookies are only sent along with requests upon top-level navigation.Lax
, cookies are sent with top-level navigation from the same host as well as GET requests originated to the host from third-party sites. For example, suppose a third-party site has either iframe
or href
tags that link to the host site. If a user follows the link, the request will include the cookie.SameSite
attribute for session cookies.
response.set_cookie("cookie", value="samesite-none", samesite=None)
Legacy
appended to cookiename. Sites can look for this legacy cookie if it does not find a cookie that was set with SameSite=None.