Software security is not security software. Here we're concerned with topics like authentication, access control, confidentiality, cryptography, and privilege management.
myModule.config(function($sceProvider){
$sceProvider.enabled(false);
});
DangerousEnableCompression
to true
in order to enable the 'per-message-deflate' extension:Example 2: The following code uses
app.Run(async context => {
using var websocket = await context.WebSockets.AcceptWebSocketAsync(new WebSocketAcceptContext() { DangerousEnableCompression = true });
await websocket.SendAsync(...);
await websocket.ReceiveAsync(...);
await websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, null, default);
});
DangerousDeflateOptions
to set the options for the 'per-message-deflate' extension:
using ClientWebSocket ws = new() {
Options = {
CollectHttpResponseDetails = true,
DangerousDeflateOptions = new WebSocketDeflateOptions() {
ClientMaxWindowBits = 10,
ServerMaxWindowBits = 10
}
}
};
WindowsIdentity.Impersonate()
method.
using System.Security.Principal;
...
//Get the identity of the current user
IIdentity contextId = HttpContext.Current.User.Identity;
WindowsIdentity userId = (WindowsIdentity)contextId;
//Temporarily impersonate
WindowsImpersonationContext imp = userId.Impersonate();
//Perform tasks using the caller's security context
DoSecuritySensitiveTasks();
//Clean up and restore our old security context
impersonate.Undo();
Example 1
impersonates the current user's security context and uses it to perform a privileged operation. After calling DoSecuritySensitiveTasks()
, the code attempts to restore the original security context, but if DoSecuritySensitiveTasks()
throws an exception, the Undo()
method will never be called and the program will continue to use the impersonated security context.Example 2: The following server page directive disables event validation.
...
<system.web>
...
<pages enableEventValidation="false">
...
</pages>
</system.web>
<%@ Page ... EnableEventValidation="false" %>
EnableHeaderChecking
property on the HttpRuntimeSection
object to false
.
Configuration config = WebConfigurationManager.OpenWebConfiguration("/MyApp");
HttpRuntimeSection hrs = (HttpRuntimeSection) config.GetSection("system.web/httpRuntime");
hrs.EnableHeaderChecking = false;
W3Clogger.loggingFields
can be configured to allow logging sensitive data such as private and system information.
builder.Services.AddW3CLogging(logging =>
logging.LoggingFields = W3CLoggingFields.All;
... )
Example 1
shows how W3Clogging can be configure, using Flag All
, to log all possible fields in Http request, including sensitive data such as ClientIpAddress
, ServerName
, ServerIpAddress
, ServerPort
, UserName
, and Cookie
.FormsAuthentication.RedirectFromLoginPage()
method issues an authentication ticket, which allows users to remain authenticated for a specified period of time. When the method is invoked with the second argument false
, it issues a temporary authentication ticket that remains valid for a period of time configured in web.config
. When invoked with the second argument true
, the method issues a persistent authentication ticket. On .NET 2.0, the lifetime of the persistent ticket respects the value in web.config
, but on .NET 1.1, the persistent authentication ticket has a ridiculously long default lifetime -- fifty years.useUnsafeHeaderParsing
property to true
. This setting enables attacks against vulnerable applications because of insufficient validation rules on HTTP headers. true
: useUnsafeHeaderParsing
is set to true.
...
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
...
Page.EnableViewStateMac = false;
public ActionResult ActionName(Model model, string returnurl)
{
// ... controller logic
}
Example 2::The following Razor code creates a form in the resulting HTML without the built-in defense against cross-site request forgery. Note that parameter
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) {
// ... form elements
}
antiforgery
is set to either false
or null
:
@using (Html.BeginForm("actionName", "controllerName", routeValues, FormMethod.Post, antiforgery: false, htmlAtts)) {
// ... form elements
}
NSURLConnectionDelegate.connection(_:willSendRequestFor:)
delegate callback method will make the system ignore the NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
and NSURLConnectionDelegate.connection(_:didReceive:)
methods.NSURLConnectionDelegate.connection(_:willSendRequestFor:)
delegate method allows the delegate to make an informed decision about connection authentication at once. If the delegate implements this method, it has no need to implement NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
or NSURLConnectionDelegate.connection(_:didReceive:)
. In fact, these methods are not invoked, so any security checks on them will be ignored.NSURLConnectionDelegate.connection(_:willSendRequestFor:)
delegate callback method will make the system ignore the NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
and NSURLConnectionDelegate.connection(_:didReceive:)
methods.NSURLConnectionDelegate.connection(_:willSendRequestFor:)
delegate method allows the delegate to make an informed decision about connection authentication at once. If the delegate implements this method, it has no need to implement NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
or NSURLConnectionDelegate.connection(_:didReceive:)
. In fact, these methods are not invoked, so any security checks on them will be ignored.NSURLConnection
object, an NSURLSession
object or an NSURLDownload
object to evaluate the trust chain. NSURLCredential
using a non-evaluated server trust:
-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * credential)) completionHandler {
...
[challenge.sender useCredential:[NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
...
}
NSURLConnection
object, an NSURLSession
object or an NSURLDownload
object to evaluate the trust chain. NSURLCredential
using a non-evaluated server trust:
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
...
let cred = URLCredential(user: "foo", password: "bar", persistence: .none)
let trust = challenge.protectionSpace.serverTrust
let cred = URLCredential(trust:trust!)
...
}
NSURLConnection
object, NSURLSession
object or an NSURLDownload
object to evaluate the server trust. In order to evaluate the server trust, the SecTrustEvaluate(_:_:)
method should be called with the trust obtained from the serverTrust
method of the server's NSURLProtectionSpace
object. SecTrustEvaluate(_:_:)
method returns two different values:OSStatus
value represents the result code.cancel(_:)
.
SecTrustRef trust = [[challenge protectionSpace] serverTrust];
SecTrustResultType result = kSecTrustResultInvalid;
OSStatus status = SecTrustEvaluate(trust, &result);
completionHandler(NSURLSessionAuthChallengeUseCredential, [challenge proposedCredential]);
NSURLConnection
object, NSURLSession
object or an NSURLDownload
object to evaluate the server trust. In order to evaluate the server trust, the SecTrustEvaluate(_:_:)
method should be called with the trust obtained from the serverTrust
method of the server's NSURLProtectionSpace
object. SecTrustEvaluate(_:_:)
method returns two different values:OSStatus
value represents the result code.cancel(_:)
.
let trust = challenge.protectionSpace.serverTrust
var result = SecTrustResultType.invalid
let status = SecTrustEvaluate(trust!,&secresult)
completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, challenge.proposedCredential)
NSURLConnection
delegate handles authentication challenges without first verifying that the application knows how to handle the authentication challenge for a particular protection space.NSURLProtectionSpace
object represents a server or an area on a server, commonly referred to as a realm, that requires authentication.NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
method will be called right before the call to the NSURLConnectionDelegate.connection(_:didReceive:)
method that should perform the authentication. This allows the NSURLConnectionDelegate
to inspect the protection space before attempting to authenticate against it. By returning true
, the delegate indicates that it can handle the form of authentication, which it does in the subsequent call to connection(_:didReceive:)
. If your delegate does not implement this method and the protection space uses client certificate authentication or server trust authentication, the system will attempt to use the user's keychain to authenticate which may not be the desired behavior.NSURLConnection
delegate handles authentication challenges without first verifying that the application knows how to handle the authentication challenge for a particular protection space.NSURLProtectionSpace
object represents a server or an area on a server, commonly referred to as a realm, that requires authentication.NSURLConnectionDelegate.connection(_:canAuthenticateAgainstProtectionSpace:)
method will be called right before the call to the NSURLConnectionDelegate.connection(_:didReceive:)
method that should perform the authentication. This allows the NSURLConnectionDelegate
to inspect the protection space before attempting to authenticate against it. By returning true
, the delegate indicates that it can handle the form of authentication, which it does in the subsequent call to connection(_:didReceive:)
. If your delegate does not implement this method and the protection space uses client certificate authentication or server trust authentication, the system will attempt to use the user's keychain to authenticate which may not be the desired behavior.NSURLConnection
or NSURLSession
fails to check what host it is sending the credentials to.NSURLConnection
or NSURLSession
callbacks to handle authentication requests. Forgetting to ensure that the authentication request comes from the expected host would result in credentials being sent to every URL the application loads. In addition, failing to check that the credentials can be sent securely would result in credentials being stolen.
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NS URLAuthenticationChallenge *)challenge completionHandler:(void (^)(NS URLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler {
NSString *user = [self getUser];
NSString *pass = [self getPassword];
NSURLCredential *cred = [NSURLCredential credentialWithUser:user
password:pass persistence:NSURLCredentialPersistenceForSession];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}
NSURLConnection
or NSURLSession
fails to check what host it is sending the credentials to.NSURLConnection
or NSURLSession
callbacks to handle authentication requests. Forgetting to ensure that the authentication request comes from the expected host would result in credentials being sent to every URL the application loads. In addition, failing to check that the credentials can be sent securely would result in credentials being stolen.
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
let user = getUser()
let pass = getPassword()
let credential = URLCredential(user: user, password: pass, persistence: .none)
completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, credential)
}
tx.origin
for authorization purposes.tx.origin
global variable holds the address of the account from where a transaction originates.tx.origin
contains the address of account, A1, used for calling S1. If the intent of tx.origin
is to verify authorization of A1, then this authorization is bypassed.tx.origin
, then tx.origin
will hold the address of the user account that initiated the transaction and authorization will be bypassed.tx.origin
before transferring funds to a provided address.sendTo
function in the vulnerable contract, then the condition within the require
statement will be true and funds will be transferred to whatever address the attacker contract specified when calling sendTo
.
function sendTo(address receiver, uint amount) public {
require(tx.origin == owner);
receiver.transfer(amount);
}
0.0.0.0/0
) the TCP port 22
, where an SSH server typically responds to incoming connection requests.
- name: Task to open SSH port
amazon.aws.ec2_group:
name: demo_security_group
description: Open the ssh port to the world
state: present
vpc_id: 123456
region: us-west-1
rules:
- proto: tcp
ports: 22
cidr_ip: 0.0.0.0/0
- name: Create Lambda policy statement for S3 event notification
community.aws.lambda_policy:
action: lambda:InvokeFunction
function_name: functionName
principal: *
statement_id: lambda-s3-demobucket-access-log
source_arn: arn:aws:s3:us-west-2:123456789012:demobucket
source_account: 123456789012
state: present