Time
5 hours 54 minutes
Difficulty
Intermediate
CEU/CPE
6

Video Description

This lesson covers defensive coding. Defensive coding is a form of proactive secure coding which is intended to ensure the continuing function of software under unforeseen circumstances and is most often when there is a likelihood that a piece of software might get misused. Defensive coding has many advantages and can solve a number of issues before they even have a chance to develop. Strong defensive coding practices discussed in this unit are: • Input validation • Sanitization • Safe APIs • Tokenizing • Sandboxing • Anti-Tampering Techniques • Secure processes for software o Version control o Code analysis o Code/peer review • Secure builds

Video Transcription

00:04
Okay, now we've looked at many of the threats and many of the potential issues that come up with our applications, whether their Web based applications or for internal use for proprietary applications. So what is our solution? What is our answer? Well, our solution is to use good coding practices
00:21
and to implement what we refer to his defensive coating.
00:25
So the idea with defensive coatings were proactive, were using good secure coding standards. And ultimately, we want to make sure that regardless of what comes up, we're prepared. We're thinking about the potential misuse of our applications,
00:41
and we're implementing security to mitigate those external threats.
00:45
Other benefits of making sure we're using defense coding. We generally have better quality software. It's better written. It's tighter. It's, um, we're closing those instances of vulnerabilities. The source code, because it follows those standards generally is more comprehensible,
01:04
Um, so that
01:07
anyone that's reviewing the code would have a better idea. Ah, and the code would be easier to understand. And ideally, we want our software to behave predictably. So if we follow good standardized coding practices, we will get predictable code. So defensive coating has a lot of benefits
01:26
over the next couple of sides will talk about a few elements of defensive coding.
01:30
Input, validation. Big, big, big. If we're gonna ask for input from the general public, we need to make sure that we validate that input is being legitimate. We do that by data typing. We limit the input, um,
01:46
length of our field. We have, ah, scripts that validate the input and check for things like that of control languages. But input validation is essential
01:57
sanitization of data. We can sanitize input as well as output. In any time we talk about sanitization, we're talking about taking something that could have malicious use or dangerous repercussions and translating it to a safe form.
02:15
So when we talk about information,
02:19
that could be very valuable. So, for instance, if I'm typing in the Social Security card are the Social Security number of an employee, for instance, maybe that information being stripped away masked out so that the information isn't there and isa service rep wouldn't have access to that information,
02:38
replacing user supplied input with safer alternatives, maybe more generic
02:44
information. So we might query, um,
02:47
a user for like we might, for instance, ask a user for their full credit card number, but we might only store the last four digits. The last four digits really aren't confidential the way the entire credit card number is, so the user may supply us with the full context of the information, but we may only store
03:07
a portion of that
03:09
output. Sanitization What's coming out from our organization? What type of output before we present it to the clients So we want a mix of coating is error handling exception handling air messages? So again, the idea here is that our errors should indicate that there's been some sort of issue with
03:29
out
03:30
divulging any sort of internal vulnerability. Ah, we want to make sure that they're non verbose because in the verbose modes, there's a lot of information that could be used in order to commit some sort of compromise.
03:46
Safe AP eyes We've already talked about the risks associated with using deprecate id AP eyes that perhaps have been exploited. A p I usages is huge, and this is what allows access from untrusted entities like applications toe access, trusted resource is like memory,
04:04
so we have to make sure that we're using safe and trusted AP eyes.
04:09
We have to think about concurrency
04:12
and concurrency is simultaneous operations. You know, if you want to think about something like two users trying to open the same file on a network share will, often that file gets locked, the first person to access that gets full access to the file and everything everybody else
04:30
would have read only access. So file locking would be a way that we preserve
04:35
issues with concurrency, Um, making sure that we have operations that are single threaded. But again, resource locking is one of the best ways to deal with concurrency issues.
04:48
Token izing taking sensitive data with unique information and really taking them and replacing them with the idea of a token that would still provide the authentication necessary. And you hear about tokens a lot with authentication. But getting rid of that sensitive that and replacing it with a token.
05:09
So, for instance,
05:10
um, you know, I provide my authentication information, my password, my user name. I have access to all of these Different resource is. So instead of having to provide that information again and again, I'm granted an access token so that when I try to access resource is in the domain. It's that token
05:29
that gives me access. I don't have to provide those credentials again.
05:31
Nor does that token store my user name and password. That token is kind of a guarantee that I've authenticated properly.
05:40
Sandbox sand Boxing is all about applications when there are files, applications, anything that presents a potential vulnerability to the rest of the operating system. Like one of the things I think about. When I hear the term sandbox, I think about Java
05:59
unsigned Java, Java applets or designated to run in an area called the Sandbox. And that sandbox is the context in which this application can run, or this apple it can run. And basically that's the browser. So
06:13
basically, what we're doing is creating an isolation point from the host operating system
06:18
so that a specific untrusted application or code can run and still keep it safe from the rest on and ideally prevent the threat to the host operating system itself. So you see this a lot with Java,
06:33
any type of anti tampering mechanisms that we want to guarantee that what's downloaded is what's been received or when we look at this file we get that assurance that it hasn't been modified Code signing for Web based applications like Javan Activex controls
06:53
when we're downloading thes. You know, Java is very powerful. Activex very, very powerful.
06:59
When I'm downloading these apple, it's or these controls. I want to make sure that I trust the entity that's providing these files or this this code, and I want to make sure that the code hasn't been modified. So code signing, not downloading these files, if they aren't digitally signed is one way we get a good assurance against tampering,
07:19
a other ideas with controlling our software version, control code analysis and peer review.
07:28
So when we talk about secure processes for our software, make sure we do version ing. Make sure that we know the correct version of code, and also that we have capability of rolling back to previous versions if that's necessary. This is a good form of change management with our code
07:46
so that we understand,
07:48
um, that there's a very specific process for making changes to the code, and each change should be tracked to a version
07:58
code analysis. That means we're gonna inspect the code. Is the code well written is it good quality are their internal weaknesses or their problems with the structure and the logic of the code? And when we talk about static code analysis, that's the pure inspection of the code. And some of this will talk more about in the testing
08:18
chapter.
08:20
But ultimately, just in looking at the coach's playing code review,
08:24
does it? Is it well written? Is it well formed? Is it logical?
08:28
Dynamic code analysis means that we're actually gonna execute the code and analyze from that standpoint.
08:35
And then, of course, code review is a very systematic evaluation of the source code. Ultimately, again, we're looking for good syntax. We're looking for structure. We're looking for logic. We want code, you know, it's very possible for code to run and be poorly written.
08:54
So in code review, what we're looking for us. We're looking for code that doesn't run efficiently
08:58
or even worse, code that runs in an insecure or unsecure manner.
09:03
So when we're looking at code reviews and again, we'll talk about a lot of this in the section on testing code. But ultimately, you know when we're doing, uh, unit tests and we're doing code review this may be part off the code design or the code writing process because we're doing it as programmers.
09:22
So we're looking for possibilities of injection non repudiation mechanisms.
09:28
Many of these areas that we've talked about are we providing sufficient cryptographic support? Um, do we have maintenance hopes left in the code for easy access? Is it possible to integrate a logic bomb? Um, are there synchronization areas? Does that leave room for race conditions?
09:46
So all sorts of things that we're looking for in code reviews
09:50
is it secure and isn't well written? Inefficient? That's our goal.
09:58
When we talk about secure builds, we're talking about more than just the developer. Creating secure code it's is access to the code protected itself because of developer can write secure code. But if we don't restrict access to that code, anybody can come in and modify it.
10:15
So often we'll talk about the use of libraries. So
10:18
while the code is in the development process, it'll go in the developers library in his under strict lock and key management, perhaps by librarian Um, we want to make sure that there's some sort of automation process that make sure
10:35
that the build itself is hander handled in a secure manner.
10:39
All right, so all of this information, there's a lot of information in this chapter as well. There should be because this is the actual implementation. This is the actual secure coding element. And this is a course where the rubber meets the road. This is where we implement the security that we've talked about up to this point.
10:58
So this is a really important chapter. We look at some common vulnerabilities.
11:03
We look at some mitigating strategies, we talk about some good concepts of coding and some potential flaws. So I would definitely encourage you to review this chapter and spend a good amount of time here because this really in the coding is where we prevent or leaks mitigate some of these threats that we've already talked about.
11:22
Following this chapter, we're gonna move into talking about secure testing
11:26
and creating an environment which we can get assurance in the code that we've written

Up Next

ISC2 Certified Secure Software Life-cycle Professional (CSSLP)

This course helps professionals in the industry build their credentials to advance within their organization, allowing them to learn valuable managerial skills as well as how to apply the best practices to keep organizations systems running well.

Instructed By

Instructor Profile Image
Kelly Handerhan
Senior Instructor