Slashdot Mirror


Secure Programmer: Keep an Eye on Inputs

An anonymous reader writes "This article discusses various ways data gets into your program, emphasizing how to deal appropriately with them; you might not even know about them all! It first discusses how to design your program to limit the ways data can get into your program, and how your design influences what is an input. It then discusses various input channels and what to do about them, including environment variables, files, file descriptors, the command line, the graphical user interface (GUI), network data, and miscellaneous inputs."

45 of 157 comments (clear)

  1. If you input ever displays as HTML by Anonymous Coward · · Score: 2, Insightful

    You'd be wise to add Cross Site Scripting attacks to your list of things to protect against.

    1. Re:If you input ever displays as HTML by borkus · · Score: 5, Insightful

      A big issue for many web programmers is failure to realize that forms and web interfaces that you provide the user aren't the only way to interact with your application. A lot of them pay attention to JavaScript validation and maxlength attributes rather than check the data on the server.

      New developers working on applications open to the internet often aren't used to developing in an evironment where programmers that don't work for their employer can access their app. All it takes for one dishonet person who knows slightly more than you to hack your app.

    2. Re:If you input ever displays as HTML by mcrbids · · Score: 4, Informative

      forms and web interfaces that you provide the user aren't the only way to interact with your application.

      So true, so true. For example (in PHP)

      <?
      if ($login='Admin' && $pass='19ak129')
      $secure=true;
      if ($secure)
      { // do something very important.
      }
      ?>

      In many cases this script's security could be bypassed by adding "&secure=true" at the end of the URL!

      I prefer to generate or define a set of values that are acceptable and check with in_array().

      EG:

      <?
      $acceptable=array('a', 'b','na');
      if (!in_array($acceptable, $_REQUEST[check]))
      die ('Sorry. Input in field "check" is invalid');
      ?>

      Or by using a regex. Assume that the input must be a number:

      <?
      $match="/[0-9]+/";
      if (preg_replace($match, '', $_REQUEST[number]))
      die ('You must put in a number');
      if (strlen($_REQUEST[number]>5))
      die ('Number you have entered is out of range');
      ?>

      You can oftentimes functionalize these so that it's as simple as:

      <?
      if ($error=Valid_Integer($_REQUEST[number]))
      die($error);
      ?>

      Simple methods that can greatly enhance security!

      --
      I have no problem with your religion until you decide it's reason to deprive others of the truth.
    3. Re:If you input ever displays as HTML by WoTG · · Score: 2, Informative

      Yeah, web applications were a mess, and bloody complex to do rather basic tasks. Fortunately, most platforms are getting better, and more conservative with age. For example, your PHP URL trick wouldn't work in a recent default installation of PHP where "register_globals" (the automagic system that makes all variables from HTTP POST, URL's, cookies, and sessions all the 'same') is "Off".

      I guess the moral of the story is that the web is young, and web platforms are even younger. With any luck, many of these headaches will disappear with time.

      BTW, anyone know of some magical code to block SQL injection vulnerabilities?

    4. Re:If you input ever displays as HTML by GAVollink · · Score: 2, Informative

      Magical!? Yes. It's really easy in fact. Simply do NOT use direct user input within an SQL statement. That seems really restrictive but it's not - it simply requires that you push back CHOICES to the user in creating your form... all sara john ...then you use the values (validated to be only numbers) to back-fill your SQL statement. If you are really feeling risky, then at the very least make sure that every character you recieve is [A-Za-z0-9 ], length verify it to make sure it matches the lenght of your field, and reject anything with single or double quotes embedded. It's not magic, it's... programming.

    5. Re:If you input ever displays as HTML by critter_hunter · · Score: 2, Interesting

      The option to register global variables is off by default since PHP 4 and for a very good reason: it's potentially insecure, as you demonstrated, and it also creates very sloppy code. Ever tried to debug a program you haven't written that uses those? You get variables that have never been declared being used, and it can be a pain to determine where exactly they come from. From an included file? $_POST? $_GET? Then you can get conflicta and it becomes an horrible mess - I can't understand why register_globals is an option, much less why it was the *default*

      --
      Karma: Could be worse (could be raining)
    6. Re:If you input ever displays as HTML by Admiral+Burrito · · Score: 3, Informative
      BTW, anyone know of some magical code to block SQL injection vulnerabilities?

      Use placeholders. PEAR DB supports them, as do other database abstraction layers. As long as you _always_ use placeholders you will be safe against SQL injection.

      If you can't depend on PEAR DB (or similar) to be installed / at the correct version, you could quickly build yourself a function that takes a variable number of arguments: a SQL statement containing '%s' (for strings) or %d (for numerics) followed by potentially hostile arguments. Run each of the arguments through mysql_escape_string (or equivalent for your DB) then build your SQL statement using sprintf. Note: I haven't tested that approach; use with caution.

    7. Re:If you input ever displays as HTML by smartfart · · Score: 2, Informative

      Not to ignore the rest of your comment, but wouldn't initially setting $secure to a null value solve that problem?

      <?
      unset($secure);
      if ($login='Admin' && $pass='19ak129')
      $secure=true;
      if ($secure)
      { // do something very important.
      }
      ?>

  2. And code reviews, code reviews, code reviews by Brahmastra · · Score: 5, Insightful

    I believe code reviews with a large enough group of people to be extremely useful. Yeah, it takes time and you get some irritating comments from a few people about how there is a space between something or comma between something, but when multiple eyes look at it, someone always catches something you didn't. A few hours of extra pain on the side of programmers can prevent pain for millions in the form of blaster viruses, etc.

  3. The more things change.... by billstewart · · Score: 5, Insightful
    One of the first lessons we learned in CS100 was to always validate the input, assuming that it might be bogus or actively malicious. I've been appalled over the last 25 years at the number of products, developers, and companies that don't understand that. Most of the internet security problems we've seen have been from inadequate handling of input data, typically the buffer overruns that are so easy to program in C if you're not paying attention.

    The article's worth reading, and really does justify it's "Level: Intermediate" label. Unlike when I was learning to program, there are lots of sources of input beyond your deck of punch cards (:-), and the author does a good job of explaining many of them, such as evil things that environment variables and file descriptors can be used for.

    --

    Bill Stewart
    New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
    1. Re:The more things change.... by agslashdot · · Score: 3, Insightful

      While I agree with you from a theoretical standpoint, I'm sure you are aware why things like this get overlooked in day-to-day corporate IT programming tasks.
      eg. Manager says, write a UI that accepts username & account, and then spits out user transactions . During design phase, you invariably make the code hack-able so its easy to test. ie. I could put in "*" for account and it would spit out transactions of ALL users, regardless of the username. This is a useful backdoor, especially in development time when your UI has to interact with somebody else's data repository in some compplicated fashion.
      Ofcourse, its a given that the input validation logic must be modified and backdoor must be taken out when the UI is actually deployed. But corporate practices being what they are, someone else takes ownership of the code at that stage, and either doesn't understand the "star-feature" ( *) , or thinks its cool to have this in case of emergency debugging, so leaves it there. Soon, this stupid program that should have been running standalone on someone's box, gets a facelift and is shoved on the internet. Some cracker comes along and puts in a star for account & gets all the transactions, & pretty soon, register.co.uk gets wind of this and reports it on front page. by then, original programmer has moved on to some other task, requiring a new back-door :)

    2. Re:The more things change.... by borgboy · · Score: 2, Informative

      Maybe the testing methodology you cite isn't so useful then, if you have to change your code when you're done testing. Backdoors are only bad if you put them in in the first place. Test First Design might be a better approach than Code an insecure backdoor as a test.

      --
      meh.
    3. Re:The more things change.... by fermion · · Score: 2, Insightful
      And the second thing I learned was to do things once and do it right. This means that input should happen in one place, the function should make sure the input will fit in the allocated space and contain only the proper data, and may even take an argument for the maximum size the calling fuction expects.

      What amazes me is that people try to optimize thier code by carefully minimizes thier input fuction. It is input. Input is slow. Go somewhere else to optimize. Create a good input fuction and leave it alone.

      The third thing I learned was to write a good validitating layer for memory allocation in C. Used as debug tool, it discover all most of the little memory problems that inevitable creep into C, as well as some buffer overflows. I know people bitch about how screwed up C is, but with the proper debug tools I had few problems.

      --
      "She's a scientist and a lesbian. She's not going to let it slide." Orphan Black
    4. Re:The more things change.... by Rich0 · · Score: 2, Funny

      The last time I checked coders in corporations got promoted for churning out the largest number of apps with the largest number of features in the shortest amount of time. The people who promote them are legitimate users of the application so they don't think to try to break it and see what happens. The security break-ins occur years after the original coder is gone.

      Besides - leaving some small holes in your code guarantees future work - which is hard to come by in this day and age.

  4. perl -T says it all by DrJimbo · · Score: 3, Interesting

    The Perl language has built-in "taint-checking" enabled via the -T command line switch which causes Perl to automatically keep track of all information that possibly came from a user input and not allow any of it to do anything harmful (basically end up on a command line or in a file name).

    --
    We don't see the world as it is, we see it as we are.
    -- Anais Nin
    1. Re:perl -T says it all by Carnildo · · Score: 5, Informative

      The Perl language has built-in "taint-checking" enabled via the -T command line switch which causes Perl to automatically keep track of all information that possibly came from a user input and not allow any of it to do anything harmful (basically end up on a command line or in a file name).

      There are other harmful things that data can wind up doing that Perl can't check for. Things like being used as SQL queries, or the classic "pass the price as a CGI parameter" mistake. Taint checking is more useful as a reminder that you need to validate input than a way of keeping potentially bad input isolated.

      --
      "They redundantly repeated themselves over and over again incessantly without end ad infinitum" -- ibid.
  5. Re:Windows & Belkin by AuMatar · · Score: 4, Insightful

    There are no controls on Windows inputs. Any process can send any message to any other process. Talk about insecure.

    You could probably majorly screw up a progoram by sending it random message numbers. It'd react as if you were sending random menu and other commands. Hmm, that sounds like a fun prank to play...

    --
    I still have more fans than freaks. WTF is wrong with you people?
  6. Murphy's Law strikes again. by Dr.+Bent · · Score: 5, Insightful

    It is a widely accepted engineering maxim that systems should be designed so that it is difficult to use them improperly. This is why (for example) a 110 volt plug will not fit in a 220 volt outlet. Developers who are concerned about the quality of the software they make would do well to follow this rule, and not just for security reasons. You should verify input data as early and as rigorously as possible wherever you can. Take advantage of things like XML validation and text box constraints to make it hard for users to enter bad data. And always follow the Fail-Fast principle...if something goes wrong: Complain! Loudly!. Don't let the user continue working if something has gone wrong. It's better to crash than to produce an erronous result.

    Just a little advice from a developer who's made enough mistakes to know better.

    1. Re:Murphy's Law strikes again. by FartingTowels · · Score: 2, Funny
      "This is why (for example) a 110 volt plug will not fit in a 220 volt outlet"

      You do not have any children, now do you? ;-)

    2. Re:Murphy's Law strikes again. by Tim+C · · Score: 2, Insightful

      Take advantage of things like... ext box constraints to make it hard for users to enter bad data

      That's good and necessary advice, but it's not sufficient, depending on your environment. If you're programming for the web, then you absolutely cannot rely on such things. Of course you should always set such constraints in the HTML where possible, but you *still* have to validate the inputs fully in your code.

      In case the reason why isn't obvious, it's because URLs are very easy to hand craft. There's no way you can stop me from sending 500 chars of data as the value of a field that you thought you'd constrained to be 10 chars. Even if you treat POST and GET differently, I can just whip up a little app to do POSTs for me if I'm so inclined.

      Front-end constraints and sanity checking (eg javascript that checks to make sure that all required fields have a value before submitting the form) are an invaluable part of the user experience, but they're no substitute for securely written code. The two things serve entirely different purposes.

      More generally speaking, you should santiy-check all input data, at all stages in the code.

    3. Re:Murphy's Law strikes again. by Rich0 · · Score: 3, Insightful

      Keep in mind that the 110 and 220 plugs are designed to defeat accidental mixups. Computer input validation is generally designed to do the same. Hardening software against an attack is more analagous to giving your engineer the task of designing a plug and outlet such that it is physically impossible to plug anything but that one particular plug into the outlet, with the understanding that somebody with a good knowledge of engineering will try to defeat the design.

      Software is required to do a lot more than any physical security measure in existance. Your webserver could come under attack by any electronic measures that you could conceive of by a host of trained software engineers in another country. Chances are that the most a bank vault is designed to handle is a dozen guys with small arms, rudimentary safe-cracking gear, and some small explosives. If the US Army showed up with an M1 tank and 1000 tons of C4, the safe wouldn't last long. However, such a large-scale intrusion is unlikely to escape the watch of the police for long. On the other hand, a remote attack against a webserver can run for months without much being done to the attackers if they're in a rogue nation.

  7. hardly surprised that we have to go through this.. by hotrodman · · Score: 2, Insightful


    And why should anyone be surprised? In this age of "I read a book on VB last week and now I'm a software engineer!" type environment?
    I am not surprised that simple things like this are rehashed over and over. This is more suited to the programmer group of people who will sort data based on string comparisons, instead of learning how to use a real algorithm to do it, or keep writing static forms, instead of learning how to use a loop with a db backend - because they don't understand true programming concepts. In other words, about 80% of the current crop of overpaid, undereducated programmers that built corporate apps.

    - Eric

  8. Perl's taint checking by Eryq · · Score: 5, Informative

    Perl programmers interested in writing secure scripts should *definitely* know about the -T (taint checking flag).

    From the FAQ:

    As we've seen, one of the most frequent security problems in CGI scripts is inadvertently passing unchecked user variables to the shell. Perl provides a "taint" checking mechanism that prevents you from doing this. Any variable that is set using data from outside the program (including data from the environment, from standard input, and from the command line) is considered tainted and cannot be used to affect anything else outside your program. The taint can spread. If you use a tainted variable to set the value of another variable, the second variable also becomes tainted. Tainted variables cannot be used in eval(), system(), exec() or piped open() calls. If you try to do so, Perl exits with a warning message. Perl will also exit if you attempt to call an external program without explicitly setting the PATH environment variable.

    --
    I'm a bloodsucking fiend! Look at my outfit!
    1. Re:Perl's taint checking by Eryq · · Score: 2, Interesting

      IIRC, the goal of -T is not to prevent you from *ever* using tainted data; it was to prevent accidents: running shell scripts with insecure $PATH variables, etc.

      Untainting a variable by extracting a subpattern usually means "I know what I'm doing: I promise that I'll extract a safe substring from this". (Whether the developer *actually* knows what they're doing is, sadly, not detectable by Perl).

      (As for -T not affecting a list passed to exec()/system(): that does seem odd, but maybe there's some Larger Purpose to it that I don't get).

      BTW: I think it would have been better if you explicitly had to invoke some function like untaint() or this_is_safe_to_use_in_shell_commands()... just to make you think about it.

      But imperfect as it is, -T beats the pants off the alternative approach that most languages give you, which is "You're On Your Own, Sucka".

      --
      I'm a bloodsucking fiend! Look at my outfit!
    2. Re:Perl's taint checking by rgmoore · · Score: 2, Informative

      The purpose of taint checking is more as a debugging tool than an absolute check on illegitimate data. This fits with the general Perl view that the function of the language is to assist the programmer rather than to constrain him. Thus if you turn on taint checking, Perl will stop you from doing things directly using tainted data, but it lets you "launder" the data by running it through a regexp. This isn't a perfect solution, but anything that was radically better would be all-but impossible to code. It won't stop a lazy programmer from using:

      $var =~ m/^(.*)$/;
      $var = $1;

      to bypass the checking (false laziness!), but that's not its purpose. What it will do is to catch many non-obvious mistakes by a programmer who's actually trying to write safe code.

      --

      There's no point in questioning authority if you aren't going to listen to the answers.

  9. Keep an eye on buffer overruns by shuz · · Score: 2, Informative

    Ya you can talk about inputs to programs and how misc. and unwanted data get in there but watch for buffer overruns because thats what can really kill your program.

    --
    There is or can be built a machine that can simulate any physical object. -Church-Turing principle
    1. Re:Keep an eye on buffer overruns by jilles · · Score: 2, Insightful

      No buffer overflows come from using flawed 1970's technology. Modern computer languages are immune to the worlds largest security problem: (i.e. buffer overflows) because they do something automatically that C programmers are supposed to do manually.

      Eliminate the buffer overflow and malicious input becomes invalid data which can be dealt with in a controlled fashion rather than executable gibberish.

      --

      Jilles
  10. What seems obvious to some... by Slick_Snake · · Score: 2, Insightful

    Is news to others. Many "Programmers" out there write code that does not do any error checking or catching and the result is all the crapware that we see today. We were all warned in our programming classes about memory leaks and buffer overflows, but they are still very prevalent in today's software. Perhaps we should all look harder at our code before selling off one it as a final product.

  11. Dividing by chrootstrap · · Score: 3, Interesting

    The recommendations on dividing the program into unsecure and secure binaries to handle setuid access in GUI's can very properly be extrapolated to non-graphical programs. This is a very good strategy for allowing relatively wild programs access to important facilities and can involve many types of IPC including memory-mapped files (with proper protection) and sockets. To really secure a client program that needs access to criticals, put it in a chroot jail and have it communicate with an outside process through (e.g.) a socket. Separating programs into safe and unsafe sections and applying different security techinques to each is far more effective, imo, than trying to secure a single, large application. It can also provide many other benefits of encapsulation, etc. The security onus shifts to handling client requests in the secure section which is usually much more easy to do.

    --
    Hacking articles at http://www.geocities.com/chroo
  12. Re:file this under: by chrootstrap · · Score: 2, Interesting

    "Given that every single way to compromise security involves bad input, it's not surprising that it's in a security magazine."

    What about program bugs that are not input related? If a program breaks when an internal timer overflows for example, or accessing a section of memory that has been deallocated. Such bugs can easily cause breaches in security as well as general system failure, all without any human intervention. It reminds me of the black out that Sterling mentions:

    http://www.lysator.liu.se/etexts/hacker/crashing.h tml#5
    --
    Hacking articles at http://www.geocities.com/chroo
  13. Secure coding documentation by Anonymous Coward · · Score: 2, Informative
  14. Re:file this under: by Anonymous Coward · · Score: 2, Interesting
    ... somebody had to put this in an fsking security magazine? ...
    The basic point is (translation: should be) self-evident, of course. And the points made in the article will (translation: should) be well-known to anyone who's spent a few years deploying apps in the DMZs that the Bigcorps use as their presence on the Big Bad Internet... but I found a few points in it and the referenced resources to add to my list as a beginner in that area.

    Basic point, I suppose, is that if you insist on using a U*ix-family OS in such an environment then you must ensure that the U*ix environment is clean at the beginning, which may well be more a matter of the procedures and quality control of the platform and the application deployment than of the individual apps.

    Oh, and btw, I thought the head of the thread was a kneejerk reaction, but - flamebait? Shame on whoever moderated it that way.

  15. Re:Hmmm... by ATMAvatar · · Score: 2, Funny

    I'm a little source code, robust and stout.
    Here is my input, here is my out.

    --
    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
  16. Re:Windows & Belkin by AtrN · · Score: 2, Informative

    See this paper. I remember reading the original document in (CACM IIRC) and was pleased to see it updated showing just how far "forward" we've come.

  17. Watch the USER! by anubi · · Score: 3, Interesting
    As long as we have no control over what the user tries to install and run in his machine, we are always going to be vulnerable to trojans.

    The proliferation of proprietary formats we are seeing that all do basically the same thing, like send sound files over the net, or view video clips, are encouraging mass downloads of programs from third party providers. These programs may well do what they said they would do, but with all this DMCA crap going on, its getting harder and harder to see if they are doing a little extra that wasn't in the bargain, like doing zombie work on the side to assist in little capers the originating author needs to pull off.

    What firewall or systems programming can stop a deliberately malicious program installed by an ignorant user? Say the program "demands" access to the internet for "verification/auto-update", then you have to set the firewall to allow this program access to the net. Now what happens? Its like giving car keys to a valet parking agent. You only have to trust he's only going to do what he says he will do. To add insult to injury, consider you generally have signed any recourse you have when you click that "I agree" button that confirms you have read and understood the EULA.

    What irritates me so about these "plug-ins", "macros", and "scripts" is that they are indeed executable. Nothing says the malicious person coding these things is gonna follow the rules. He is free to code some really nasties in assembler if he so desires. The state of music file distribution I find really disturbing. We have an MP3 format which is generally well understood, yet it seems everybody jumping on the bandwagon wants to use proprietary formats which are not generally understood, leaving us all open to the risks resulting from ignorance.

    As a public, we aren't helping much. We agree to any damn thing they print in the EULA. As a public, we should INSIST that if we are to be kept ignorant by law how something works, if that something does something malicious, then its maker should have full responsibility for the problems it generated.

    Basically I am proposing a trade. If you want the protection of law to keep the public ignorant, then you waive indemnity.

    We have a patent system and copyright system in place. Both were implemented on the concept that the work was to be in the open. Why aren't encrypted work also known as "trade secret" and not afforded protection by copyright or patent? Basically, any work encrypted would be considered a "trade secret", not in the open, hence not eligible for protection by the patent or copyright system at all? But to make this happen, its gonna take the will of a lot of people to pressure the legislators to enact this. Pressure as in "if you do not do this, start polishing your resume.".

    --
    "Prove all things; hold fast that which is good." [KJV: I Thessalonians 5:21]

  18. Perl security article in SysAdmin magazine by merlyn · · Score: 4, Informative

    I wrote a similar article recently for SysAdmin magazine, although the focus is more about Perl.

  19. This was well documented in the 1970's by pcause · · Score: 3, Insightful

    The Kernighan & Plauger book "Elements of Programming Style" dated 1979 talked extensively about the need to validate all inputs to subroutines and from the user. This is *not* new, it is just that few programmers have the discipline to follow the rules.

    The issue is making *no* assumptions about anything. The programmer *thinks* the file will be written be another piece of code that a team member is writing. But that program has a bug. or three years from now, other programs are creating the file and don't know abut some verbal discussion about field data. It takes great dligence and paranoia and management that allows you the time in the schedule to do this.

  20. environment variables by MellowTigger · · Score: 3, Funny

    The article is interesting, and they are right to point out the many dangers of relying on environment variables. Where I work (unidentified to protect the incompetent), programmers are not allowed access to the unix command line. Instead, all user exits are trapped, and programmers are forced to navigate through a homegrown menu system.

    This menu system relies on an environment variable ${WHATCANIDO} to store a list of permissions available to that user. Of course, I changed my .profile to add my own extension to the permission list. I even nicely dated, initialed, and described my change. ;)

    export WHATCANIDO=world_domination:$WHATCANIDO # 2000/10/31 tw Too easy

    So now when I get frustrated with the absurdity of this arrangement, I just take echo the environment variable to remind myself why I'm right and they're wrong.

    > echo $WHATCANIDO
    world_domination: [deleted]

  21. What about BIOS? Do you have to trust something? by G4from128k · · Score: 2, Insightful

    Somewhere along the line every application must trust something. At the very least, BIOS settings and environment variables that are owned by deeper layers of the OS must be trusted because they are inaccessible or indecipherable at the application layer. Reaching too far would break encapsulation and create brittle dependencies. An application can only check the variables and direct inputs that it has access to.

    I don't argue against validating inputs. Certainly all of the direct inputs to an application should be assumed to be untrustworthy unless a secure checksum validates that the inputs are indentical to some previously validated inputs. Checking inputs (or environmental variables) of immediately adjacent processes is probably also warranted (as a redundant "brother's keeper" policy).

    The real problem comes if the OS has a faulty validation methods. (And I won't get into the neccessity of trusting the hardware or bugs such as those that plagued the early Intel 586.00001 processors) If I check the validity of a user, filename, or geographically localized data format (e.g., a date), then my application is dependent on the quality of the OS's validator (and a lack of intervening malware).

    --
    Two wrongs don't make a right, but three lefts do.
  22. Problem: Hacker Languages by cryptoluddite · · Score: 2, Interesting

    Almost everything in this article only applies because of hacker languages like C and C++, which Linux and FreeBSD use for virtually everything. It is so easy to forget to double-check bounds, input format, pointers, and all the other usual suspects. It's bizarre how programmers will use these error-prone languages for marginal performance gains just because their ego and haxor status is on the line. Sure, the kernel and drivers need to be in C. Sure, a Java VM needs to be in C. Sure, C++ is a good langage for game engines. But almost nothing else should be written in C/C++.

    Command-line type programs can be written in Java and statically compiled into small, low-memory, fairly fast programs. And the JVM overhead is has almost no affect on the larger programs. But you have to work really hard to put a security problem into a Java app instead of working really hard not to. And you get garbage collection, an awesome API, security, faster compiling, dynamic classloading/linking, easier coding, etc. People think Java takes a lot of memory, is slow, and ugly. But that's almost entirely because of the Swing GUI, which is not actually all bad. Replace with IBM's SWT and you'll see a dramatic difference.

    Of course there are other languages besides Java that protect against security problems, but few that do so as completely and easily. If half the effort had been put into inplementing the Java APIs in open source as just on GTK/GTK+ then linux/bsd could do nothing for ten years and still be ahead of the rest.

    1. Re:Problem: Hacker Languages by BattleTroll · · Score: 4, Insightful
      "But almost nothing else should be written in C/C++"

      What world are you living in? Blaming poor technique on the tool used is moronic. There are ample examples of poorly written, poorly secured Java code the invalidate all of the premises in this rant. I've seen hard coded passwords baked into java source that were visible through a 'strings' call. Someone forgets to obfuscate his or her classes, and the entire structure of the program is available through a reverse compiler. Sure, the JVM protects one from buffer overruns and the like but don't for one minute think that programming in Java prevents stupid errors from exposing you to vulnerabilities.

      Not to mention there are areas where java is not the silver-bullet you describe. If you need precise control over your memory allocation, java is not the tool to use. If your application requires precise timing, java is not the tool to use. Need to control over the placement of allocated memory? Writing your own transport layer? Need hooks into the kernel?

      The prime directive still holds true - use the correct tool for the job at hand. Follow the lemmings of "this tool is the only one you need" at your peril.

  23. Re:No inputs = useless? by sir99 · · Score: 2, Insightful

    Your examples don't take user input, but most of them do take input of a different sort. The point of the article was that input can come from unexpected sources like environment variables, and that an attacker can sometimes subvert these inputs. The cpu meter, bg, fg, ps, top, logout, and clock programs all take input, in the form of system and library calls. Some of them also read input from configuration files.

    --
    The ocean parts and the meteors come down
    Laid out in amber, baby.
  24. OK, what do you do when you validate it? by Latent+Heat · · Score: 2, Insightful
    Yes, I am a believer in defensive programming, but I am not sure that defensive programming is the golden hammer. Verity Stob made a remark about taking a sick program and filling it with try-catch blocks to try to recover from every possible error condition -- I believe she called it "nailing a corpse on a tree" or some such thing. And her other remark was "the only place we seem to get exceptions is in destructors, so what's the point?" That had me on the ground in tears of laughter because destructors (freeing up resource in the right order) is one of the hardest things to get right.

    Ok, every last subroutine validates every last input. Then what do you do? Suppose an input is invalid -- do you halt? Throw and exception? Patch the input and keep going? Keep going but make an entry in a log file?

    It is excellent policy to be ultra paranoid about user input and to put "firewalls" between major program modules. But for every last subroutine to have its own error checks -- what if you have a top level subroutine that performs error checks and than passes validated results to helper subroutines? Do the helper subroutines need to repeat the checks?

    I think there has to be some analysis of the data flows and designation of raw and filtered data flows, who does the filtering, and what assumptions or assertions can be made about filtered flows, and assignment of responsibility to do the checking.

    In summary 1) defensive programming is not a substitute for good overall design, 2) there is a place for delegating responsibility for error checking and not chronically worrying about checked data.

  25. Re:Windows & Belkin by kasperd · · Score: 2, Informative

    Any process can send any message to any other process. Talk about insecure.

    Accourding to http://security.tombom.co.uk/shatter.html it is much worse than just that. Not only can anyone send such a message, but the messages can even force the receiver to execute arbitrary code.

    --

    Do you care about the security of your wireless mouse?
  26. Re:Have a no-front-end-checking mode by sjames · · Score: 2, Insightful

    That's a good point. I have seen developers mistake javascript for sufficient input validation. The proper use of validation in javascript is to simply give a legitimate user a proper error message quickly without actually needint to perform a transaction with the server that will fail. The server must still re-validate the input.