Home > Articles > Web Services > XML

Tipping the Scales Toward Secure Code

Everybody can use more secure code—and sometimes the best way to hone your skills is by listening to other programmers. Here are 18 tips offered by your fellow developers.
Like this article? We recommend

Tipping The Scales Toward Secure Code

By Rebecca Rohan
June 15, 2004

Everybody can use more secure code—and sometimes the best way to hone your skills is to listen to other programmers. Here are 18 concise tips offered by your fellow developers, each a specific (and opinionated!) piece of advice that you can put to work immediately. You may not agree with all these suggestions, but each is worth contemplating.

Be Careful What You Call

"If your application calls a DLL or another program, make sure you call it specifically," says Joshua Levy, senior software engineer for Reasoning Inc. in Mountain View, CA. "Don't rely on relative paths or search paths. The danger here is that you will end up calling a different program or DLL than you expected. This is the ultimate security flaw, because suddenly you're running a program or DLL written by the attacker! This is often a problem with 'inside jobs,' where an employee is trying to get more permissions than he should, or [to] read data or files that he isn't allowed to read. We review other people's code, and I see a huge amount of these sorts of errors." Levy writes programs to find and report such weaknesses. "It's better to check that the executable or DLL is what you expected, using signing or CRC," he suggests.

Security Focus

"Get someone to review your code specifically for security," reccomends Levy. "We've got huge QA departments that look for defects, but we don't have similar organizations that look for security vulnerabilities. Companies don't spend money unless they can see the value. When your security audit is done by a third party, you get the benefit of their expertise without the danger of your internal politics."

Church and State

"Code is secured by testing and review procedures — and the test-and-review team should be separate from the development team," says Paul Smith, CTO of PRRN Enterprise Solutions Group of Los Angeles, CA. "The objective is to ensure that only the code required to implement the function is included as part of the source, and to look for things like back doors, and things that don't relate to what the code is supposed to do."

How Authentic Are You?

"For any network application, authenticate early; authenticate often," says Dan Kaminsky, Senior Security Consultant for Avaya Inc.'s Enterprise Security Practice. "Every transaction needs to be tied to an authenticated context. As an attacker, the first thing I'll do is gauge the amount of functionality accessible without me possessing any credentials. I may have compromised another machine with the same software. I may know the underlying content of the site—and use this knowledge to expand my awareness of unauthenticated functionality exposed by the site. From there, my goal is to use the unauthenticated functionality as a backdoor to functionality that should require authentication."

Tough Love

"Don't trust the user," says Kaminsky. "Once they log in, watch for things they shouldn't do and lock them out." No letting them come at you again and again, trying sharper knives.

"[A hacker can] go to a Web site and click on all the buttons to see what they let [him] do," says Kaminsky. "Ninety-five percent of the buttons you need to log in require credentials. He finds something open, downloads the page, and sees something administrative—database setup scripts someone forgot to delete—a script to add a new user. He adds himself. He uses it to get around permissions."

Don't Let Your Cookies Crumble

"Encrypt your cookies, so that users can only reflect them back to you unchanged," says Kaminsky."Otherwise, malicious users can simply subtract from their given session ID and browse the resources available within other sessions."

Escape Evil Characters

"The key to sanitizing user input," says Anton Rager, Sr. Security Consultant and penetration tester for Avaya BCSI's Enterprise Security Practice, "is to make sure that you're escaping out evil characters that may be interpreted by the process of whatever you're sending them to. Make sure that characters that relate to the Web server or command processor or SQL server or URLs or Meta data tags, depending on what you're passing the data to, are trapped out. This requires some contextual thought."

Step Gingerly Around Your Own Feet

To make sure you're not overwriting any patches that were already installed, "Run Microsoft's Baseline Security Analyzer, a component on Microsoft's Web site for analysts and developers, while developing install scripts," recommends Robert Brown, owner of UltraTech Web Solutions of Fontana, CA.

Look Where You Are — and Where You Aren't

"Don't underestimate the environment where a program can be used," counsels Seth Fogie, VP of Product Management, Business Development and Marketing for Airscanner, Dallas, TX. "Even PDAs are susceptible to buffer overflow attack. There are programs that run on the PDA that allow a remote user to connect and execute their own code without any authorization or authentication problems. Trojans similiar to NetBus and Back Orifice are available on PDAs—and there are no indications that they're there," says Fogie. "You have to consider the environment you're programming for, consider the risks associated with the environment, consider how it could be used in an alternative environment, and how it could be abused in that."

Keep the Nuts Out

"Make sure the correct permissions are set on Internet directories so people can't download your code," says Marc Hansche, president of ACES, in San Marcos, California. Make files readable or writable with care. "Some people just set everything to 777 to make something work, and move on," says Hansche. It's the biggest hole in Web sites that you'll find." And disable directory browsing!

Don't Let Them Talk To Themselves

"If a malicious user is allowed to enter raw HTML tags and JavaScript, and this input is displayed unfiltered to other users, the malicious user will be able to steal other users' session information and obtain confidential data. This is a 'Cross Site Scripting' attack," advises Paul Keister, Principal of San Francisco-based PJPM.

Clear Is Not Cool

"Put the password in the database in encrypted form instead of plain text," says Yitzchak Ehrlich, principal of Dynamic Ventures Inc. of Cupertino, CA. "Encrypt information about how to access the database."

Do You Validate?

"Add a signature to configuration files to make sure they have not changed," says Ehrlich. "Validate data so the user only enters an expected range, instead of, say, coming to a field for their name and typing a command to the database to delete the table and set the password for the main user to be ABC." You need to protect against SQL injection.

War Room

"Sit down and approach it systemically," says David Randolph, president of Prairie Trail Software, Inc. in Plano, TX. "It's more important to say what kind of attacks are going to come in. For example, on a point to point basis, people are dialing in and using normal protocol: Don't use normal protocol! The first level protocol [that] people use is SLIP or PPP. I'm familiar with several other protocols that don't behave the same way as SLIP or PPP. What's the cost? What's the benefit? Provide sufficient challenges so that most of the people give up before they get to the stuff that's good."

Know Your Enemy — Don't Let Him Know You

"Remember, security is people," says Randolph. It's people designing code. It's people trying to break it. Hackers try things one place and try again." Once they break in one place, they learn things that make it easy for them to get around the next place with similar furnishings, so write in some speed bumps.

Watch Your Language!

"Don't use C++," says Bradford Bingel, Managing Director of ITM3, in Walnut Creek, CA. "If you were to save a character string into a variable, then later [you] came back and saved a larger character string into the same variable, you might inadvertently overwrite an unprotected area of memory," says Bingel. "That's a security issue. Today's programming languages don't have a lot of inherent security built into them. Java's an exception, as is .NET."

"A primary issue in writing a secure application is whether it uses a managed programming language or [if it's] non-managed," says Kevin Coyle, security consultant and principal of KJC.com, Dallas, TX. Managed examples are Java and C# instead of C and C++, in which you do your own memory management. This can lead to buffer overflows and stack overflows (you can use stack canaries), says Coyle, though you can have integer overflows in managed languages like Java.

"No" To the Flow

Coyle points out that tools, such as stack canaries in Visual Studio.NET and Linux StackGuard, can help with stack overflows, which have probably been a problem for twenty years. But a much more recent phenomenon, heap overflows, "are currently the most dangerous type of overflows, because the software allocates the memory dynamically from the heap, and hackers work on causing them." Coyle says libraries help; his personal recommendation is ElectricFence.

Rough Fuzzies

"People look for somebody to audit code, but they're hard to find, and it costs a lot so they end up doing it themselves," says Coyle. "There are tools to do fuzzing — program stress testing. Hackers don't have access to source [code], so they hammer away, trying to cause an error and find out the security implications." Fortunately, the fuzzing tool Spike is free.

Feel your security senses tingling? Your code will get tighter if you just keep thinking about this stuff and respecting the paranoiac within you!

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020