Slashdot Mirror


Flawed Online Tutorials Led To Vulnerabilities In Software (helpnetsecurity.com)

An anonymous reader quotes Help Net Security: Researchers from several German universities have checked the PHP codebases of over 64,000 projects on GitHub, and found 117 vulnerabilities that they believe have been introduced through the use of code from popular but insufficiently reviewed tutorials. The researchers identified popular tutorials by inputting search terms such as "mysql tutorial", "php search form", "javascript echo user input", etc. into Google Search. The first five results for each query were then manually reviewed and evaluated for SQLi and XSS vulnerabilities by following the Open Web Application Security Project's Guidelines. This resulted in the discovery of 9 tutorials containing vulnerable code (6 with SQLi, 3 with XSS).
The researchers then checked for the code in GitHub repositories, and concluded that "there is a substantial, if not causal, link between insecure tutorials and web application vulnerabilities." Their paper is titled "Leveraging Flawed Tutorials for Seeding Large-Scale Web Vulnerability Discovery."

96 comments

  1. We all know why by wonkey_monkey · · Score: 3, Funny

    Researchers from several German universities have checked the PHP codebases of over 64,000 projects

    The researchers identified popular tutorials by inputting search terms such as "mysql tutorial"

    Ah, I see where they went wrong. They should have searched for "real mysql tutorial."

    --
    systemd is Roko's Basilisk.
    1. Re: We all know why by Luc+X.+Ifer · · Score: 1

      We know that 95% of the coding bootcamps in South Asia can't code, so obviously the only way they can get something done is by copying what they find googling. Sad state of the industry.

    2. Re: We all know why by Luc+X.+Ifer · · Score: 1

      Correction '95% of the coding bootcamps products'

    3. Re:We all know why by JustAnotherOldGuy · · Score: 2

      Ah, I see where they went wrong. They should have searched for "real mysql tutorial."

      That's deprecated, now we use really really for sure this time mysql. It's webscale.

      --
      Just cruising through this digital world at 33 1/3 rpm...
    4. Re: We all know why by JustAnotherOldGuy · · Score: 1

      How do you figure that Rust will somehow be better? Bad code can be written in any language, including Rust!

      ^^^^ This.

      Pick your favorite super-safe language (if it even exists yet) and I'll personally show you how to write bad code. Really, really bad, unsafe code.

      I'm not saying that I've made every mistake in the book but I've probably added a few.

      --
      Just cruising through this digital world at 33 1/3 rpm...
    5. Re: We all know why by wonkey_monkey · · Score: 1

      How do you figure that Rust will somehow be better?

      When did I say that?

      --
      systemd is Roko's Basilisk.
    6. Re: We all know why by Aighearach · · Score: 1

      You've got more bugs than just that one, maybe you should have googled it?

      For example, "what they find googling." Who is doing the googling here? The thing that they found, according to you. But no, actually the tutorial isn't googling at all! Just a one word bugfix, of course, but still! That's the sad state of the interwebs, to be sure.

    7. Re: We all know why by phantomfive · · Score: 1

      Especially since the things that Rust does well (avoiding memory leaks and overflows) have absolutely nothing to do with the errors mentioned in the summary (SQL injection and XSS). Your code can be absolutely leak free and still have an SQL injection, it's a problem of the API not the language.

      --
      "First they came for the slanderers and i said nothing."
    8. Re: We all know why by Anonymous Coward · · Score: 0

      How do you figure that Rust will somehow be better? Bad code can be written in any language, including Rust!

      ^^^^ This.

      Pick your favorite super-safe language (if it even exists yet) and I'll personally show you how to write bad code. Really, really bad, unsafe code.

      I'm not saying that I've made every mistake in the book but I've probably added a few.

      Only idiots argue that safe languages can or should prevent programmers from writing bad Fortran in the language. Safe languages make it must easier to prevent yourself from *accidently* writing unsafe code. People who are only good at chaining stack overflow answers into a "working" program cannot be helped by programming language design. Those people can only be helped by enforcing peer review of their code, and/or not using their code.

    9. Re: We all know why by Anonymous Coward · · Score: 0

      haha, I guess you haven't been to an american university in a while....

    10. Re: We all know why by Anonymous Coward · · Score: 0

      No, the problem is that we need to get rid of html, css, and all that insecure madness and do everything in PURE JAVASCRIPT.

    11. Re: We all know why by Anonymous Coward · · Score: 0

      Well, code monkeys in the US aren't that different, but putting up tutorials without those vulnerabilities solves the problem much cheaper than trying to teach people how to code.

    12. Re:We all know why by arglebargle_xiv · · Score: 1

      Naah, they should have used StackOverflow's programming tutorials instead.

    13. Re: We all know why by Anonymous Coward · · Score: 0

      i forsee a "how many does it take" joke coming.

    14. Re: We all know why by JustAnotherOldGuy · · Score: 1

      Especially since the things that Rust does well (avoiding memory leaks and overflows) have absolutely nothing to do with the errors mentioned in the summary (SQL injection and XSS).

      Exactly.

      --
      Just cruising through this digital world at 33 1/3 rpm...
  2. I care less and less... by Anonymous Coward · · Score: 0

    First the Archive.org madness, and now this... It's just one thing after another. Idiocy upon idiocy... I cannot find the energy anymore to really care about any of it. I can't control it, nobody listens to my voice, and it doesn't *really* affect me as I code everything on my own or VERY carefully look through the "snippet" of code if it's something really specific yet complex that I need.

  3. What do you people expect? by DontBeAMoran · · Score: 0

    People learn not by memorizing but by looking at examples.

    Most of the people working in Web-related jobs are not security experts, their job is to get things done as quickly and cheaply as possible. You might think in terms of huge corporations were IT is divided in groups, each working on specific parts of the whole. At the smaller scale though, the same person responsible for the front-end with HTML, CSS and Javascript has to work on the back-end with PHP and MySQL. The second their code does what it's supposed to do they just keep going to the next item to be completed.

    So really, blame the examples and especially the tools. This is a similar problem to languages that allow you to point outside the bounds of an array or operating systems that can't protect themselves from applications gone rogue. Security should be part of the OS, part of the languages, part of the frameworks. Only then can you blame the coders at the bottom for security holes.

    --
    #DeleteFacebook
    1. Re:What do you people expect? by JustAnotherOldGuy · · Score: 1

      People learn not by memorizing but by looking at examples.

      This very true, especially in programming. The result is that bad code gets propagated with the best of intentions.

      I do fault many of the tutorial writers for not mentioning stuff like cleaning up form data and the like. They should learn what they're doing before they try to teach it.

      --
      Just cruising through this digital world at 33 1/3 rpm...
    2. Re:What do you people expect? by Anonymous Coward · · Score: 1

      People learn not by memorizing but by looking at examples.

      Looking at examples is fine and can be beneficial. However, it's important to understand what the example is doing and why. Without sufficient knowledge of the programming languages used and at least passing familiarity with the context, it's all too easy to misunderstand and either cut and paste verbatim code that's inefficient or inappropriate for production or worse, has security vulnerabilities or other bad practices. This is especially problematic with example code found in tutorials since key security practices or even outright "you shouldn't do this in production code" techniques are employed to simplify the example for instructional purposes or to highlight a particular technique by stripping out or simplifying elements that aren't directly applicable, even though this may have the effect of reducing or eliminating security or efficiency.

      Most of the people working in Web-related jobs are not security experts, their job is to get things done as quickly and cheaply as possible.

      You speak as if this is an acceptable or even laudable practice. This is one of the reasons that other engineering professions don't take software development seriously as an engineering discipline. How would you feel if the automotive engineers who designed you car were not "automotive experts" and took shortcuts to design your vehicle as quickly and cheaply as possible?

      At the smaller scale though, the same person responsible for the front-end with HTML, CSS and Javascript has to work on the back-end with PHP and MySQL. The second their code does what it's supposed to do they just keep going to the next item to be completed.

      That is an irresponsible and ultimately self defeating process. The wild west days of the web are long gone. You're never going to compete with Amazon or Facebook or any other established business like that. You've already missed your chance. The time to start businesses like that was 1994 not 2017.

      So really, blame the examples and especially the tools.

      The people who follow and use them mindlessly deserve the blame.

      This is a similar problem to languages that allow you to point outside the bounds of an array or operating systems that can't protect themselves from applications gone rogue.

      These sorts of checks are not free. Depending upon the context, it can be appropriate to forgo them. The choice was and is left up to the programmer and the system designer, which is as it should be. The right tool for the right job. It's a poor engineer who blames his tools.

      Security should be part of the OS, part of the languages, part of the frameworks. Only then can you blame the coders at the bottom for security holes.

      Some people just shouldn't be in this business, including many of the so-called "coders" who handle outsourced projects, typically in India but self taught Americans and Europeans also contribute their fair share of crap to the swimming pool.

    3. Re:What do you people expect? by dgatwood · · Score: 1

      Where I used to work, we called this the "Stack Overflow Effect" because so much bad code written by well-meaning people was floating around Stack Overflow that did things in dangerous, security-risky ways, such as telling people to disable TLS chain validation so they could use a self-signed cert for their test environment, then wondering why so many apps shipped with chain validation turned off in the production versions of the app.

      I've actually written security documentation whose primary purpose was to provide a single set of code snippets that were known to do things in the right way so that we could plaster Stack Overflow with links to the doc. Then, when people say, "but can't I just...", we can say, "No", and point them atdocumentation explaining why so that at least when they do something stupid anyway, we can say, "Dude, what part of 'no, that is incredibly dangerous' didn't you understand?"

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    4. Re:What do you people expect? by Anonymous Coward · · Score: 0

      People learn not by memorizing but by looking at examples.

      Looking at examples is fine and can be beneficial. However, it's important to understand what the example is doing and why. Without sufficient knowledge of the programming languages used and at least passing familiarity with the context, it's all too easy to misunderstand and either cut and paste verbatim code that's inefficient or inappropriate for production or worse, has security vulnerabilities or other bad practices. This is especially problematic with example code found in tutorials since key security practices or even outright "you shouldn't do this in production code" techniques are employed to simplify the example for instructional purposes or to highlight a particular technique by stripping out or simplifying elements that aren't directly applicable, even though this may have the effect of reducing or eliminating security or efficiency.

      Dunning-Kruger. Programmers with appropriate levels of abstract reasoning can tell when they don't know something. People with high levels of abstract reasoning can correctly tell if they know something 70%+ of the time. People with low abstract reasoning are only correct 10% or less of the time. If you can't tell when you're wrong, the only way you'll learn is by making mistakes or someone holding your hand.

  4. I believe it by JustAnotherOldGuy · · Score: 4, Insightful

    I believe it.

    I've come across countless tutorials that cover things like capturing and using form field input, but almost NEVER see a single word in them about sanitizing data, or guarding against bad, malformed, or malicious data.

    It's just, "Here's how ya get the data, now go jam it in the database or print it right to the screen!" Fuck me.

    And in all fairness, as a PHP user, I've seen a *lot* of PHP tutorials that were bad, stupidly dangerous, or just plain wrong. One of the most egregious was a "tutorial" that showed sending the entire SQL statement to the server as a GET parameter. That's right, some guy actually coded his shot so that it sent a live SQL statement in the URL, and then blithely processed the attached variables without so much as a how-de-do.

    Later I saw code that did this exact thing used in various scripts (guestbooks, registration forms, comment forms), probably based on this epically flawed "tutorial".

    --
    Just cruising through this digital world at 33 1/3 rpm...
    1. Re:I believe it by DontBeAMoran · · Score: 1

      I've seen similarly bad tutorials about templating. The way they teach how to cut your basic HTML and CSS apart in chunks is complete nonsense. They're showing people to always copy a whole empty framework and call cut-out parts all over the place. And then inside those cut-out parts, call out other parts. I've seen this done five levels deep.

      It still works, but trying to way your way around all is extremely tedious. And if you need to make a change to the basic original framework, you're out of luck because the idiots made that code NOT part of a template and replicated it manually in all the pages of the website.

      --
      #DeleteFacebook
    2. Re:I believe it by JustAnotherOldGuy · · Score: 1

      I've seen similarly bad tutorials about templating. The way they teach how to cut your basic HTML and CSS apart in chunks is complete nonsense. They're showing people to always copy a whole empty framework and call cut-out parts all over the place. And then inside those cut-out parts, call out other parts. I've seen this done five levels deep.

      That sounds like Smarty. What an abomination.

      Jeezus, I hadn't thought about Smarty in years. Now I need a Xanax.

      --
      Just cruising through this digital world at 33 1/3 rpm...
    3. Re:I believe it by Anonymous Coward · · Score: 0

      One of the most egregious was a "tutorial" that showed sending the entire SQL statement to the server as a GET parameter. That's right, some guy actually coded his shot so that it sent a live SQL statement in the URL, and then blithely processed the attached variables without so much as a how-de-do...Later I saw code that did this exact thing used in various scripts (guestbooks, registration forms, comment forms), probably based on this epically flawed "tutorial".

      This is what happens when the project is outsourced to Indian code monkeys who cannot be bothered to give two shits.

    4. Re:I believe it by CaptnCrud · · Score: 2

      I see stuff like that all the time as a full stack contractor, and some places just don't understand why the code needs to be refactored or completely canned and replaced.

      That's also how bad code "infects" whole projects too, the worst offenders are oddly enough System admins and network engineers trying to rapidly prototype something it seems.

      Here is how it goes down, after cobbling together some code they used google to assemble.....they call it good and put it into production ASAP because the fire is under their ass and they need to get everything up and running. Later (assuming the bullet was dodged an none the wiser), new coders come in and copy paste what the "senior developers" who are now managers did...and the issue propagates from there.

    5. Re: I believe it by Brockmire · · Score: 1

      +5 Insightful

    6. Re:I believe it by hey! · · Score: 2

      I've been saying this for years: the reason that the same stupid security holes keep popping up is that they keep showing up in the tutorials that people use to learn new systems and languages.

      The cognitive burden of learning a new system is rough on most people, so it's tempting to make things easy on them. In fact you might have higher satisfaction from students if you do. It certainly makes them feel like they're learning more for less effort if they can make something happen that looks right. But you should never, ever model a bad practice for beginners, even if you have the intent of going back and explaining to them that they shouldn't do it that way. It's better to say, "OK, you don't understand this particular bit, but don't worry I'll come back to it later."

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    7. Re: I believe it by Anonymous Coward · · Score: 0

      Hey now, don't you go dragging the sysadmins into this; if the devs had tested or at least documented their shit before just tossing it over the fence, the sysadmins wouldn't have those fires to put out to begin with. :D

    8. Re:I believe it by Anonymous Coward · · Score: 0

      Input validation is hard. Example.

      Input validation means you need to understand the different class of formal languages, what they can or cannot do, and how a data model can be built using the knowledge of formal languages. Then you also need to understand the standards.

      Try uttering the words "context-free grammar", or even just "EBNF" to the average "coder" and see the eyes glaze over.

    9. Re:I believe it by Anonymous Coward · · Score: 0

      I've come across countless tutorials that cover things like capturing and using form field input, but almost NEVER see a single word in them about sanitizing data, or guarding against bad, malformed, or malicious data.

      I wouldn't sanitise the data. That's just 'corrupting data' by a nicer name. The data the user input shall go through my code unblemished.

      There is very little a user can input that cannot be stored in a varchar() column in a database.

      It's just, "Here's how ya get the data, now go jam it in the database or print it right to the screen!" Fuck me.

      Jamming user input into the database is exactly what I do. But I do mind the context: if it's SQL, I use placeholders in my query, or if that fails I escape the single quotes etc; if it's HTML I'm outputting, I most certainly escape the four or five characters that have special meaning. <>&";

    10. Re:I believe it by michael_wojcik · · Score: 1

      Yes. And not just you-get-what-you-pay-for free online tutorials, either. I've seen more than one programming textbook (including for this very case - PHP applications with a MySQL database) that describe in loving detail how to construct ad hoc SQL queries using string concatenation and interpolation, say.

      And on the output side, show interpolating user-controlled, unsanitized data from the database directly into the HTML output stream. Maybe there's a half-assed throwaway attempt at anti-XSS, at best.

      These textbooks may have gotten better in recent years (it's been a few since I gave up on them), but of course students will often pick up used copies of old editions.

      Now, I'll be the first to admit that we have a structural problem when it comes to teaching this material to students. There are plenty of undergrad "build a web application" classes which simply do not have time to deal with security in any reasonable way. That's a curriculum-development and academic-program-development issue, and it's not easy to solve. (You could easily spend most of the semester going over the OWASP Top 10+2 in an undergrad course.) But there's a ton of bad information out there.

    11. Re:I believe it by JustAnotherOldGuy · · Score: 1

      ... that describe in loving detail how to construct ad hoc SQL queries using string concatenation and interpolation

      There's nothing inherently wrong with that as long as you're sanitizing your inputs properly and/or using parameterized queries.

      --
      Just cruising through this digital world at 33 1/3 rpm...
    12. Re:I believe it by michael_wojcik · · Score: 1

      Yes, fine, I wasn't specific enough. The texts in question describe how to construct such queries using tainted data. Happy?

      And, frankly, as an IT security professional I'm not satisfied with sanitization in this case. Sanitization tends to be fragile and more complicated than non-experts think, so it often fails to cover all cases. While it can be useful for defense in depth (particularly with whitelisting; whitelisting valid input patterns and rejecting everything else is far safer than approaches that rely on escaping), it's a poor approach to preventing injection. There's really no excuse for it, except when the vulnerable code is inaccessible - e.g. in a third-party binary that's no longer supported but can't be retired.

      All database operations should use parameterized queries or stored procedures (and the stored procs should not be assembling unsafe queries either, of course). And they should be in a DAL, not mixed in with business or presentation logic. The textbooks I'm referring to utterly fail at separation of concerns, too.

    13. Re:I believe it by JustAnotherOldGuy · · Score: 1

      Yes, fine, I wasn't specific enough.

      I forgive you.

      --
      Just cruising through this digital world at 33 1/3 rpm...
    14. Re:I believe it by michael_wojcik · · Score: 1

      OK, I admit that made me laugh.

      It's all in the delivery.

  5. Protect you against SQL injection? Really? by HBI · · Score: 3, Insightful

    I would love to hear the explanation of how a general purpose language would protect you against attacks like that, clearly called out in the article.

    You're doing the snowflake thing, blaming everyone else for the coders' incompetence and unsuitability for the job. Some dweeb wrote a tutorial and because it's not ready to be cut and pasted into production code, that's the tutorial writer's fault.

    NB: Not everyone can code.

    --
    HBI's Law: Frequency of calling others Nazis is directly correlated with the likelihood of the accuser being Communist.
  6. Re:Protect you against SQL injection? Really? by DontBeAMoran · · Score: 1

    If a bridge collapses, do you blame the production workers who followed the plans exactly as they were or do you blame the engineer who was too lazy to make the proper calculations and didn't get the tests done for the bedrock foundation, etc?

    You're doing the popular "snowflake attack" thing here, when in fact you're the snowflake thinking that everyone is as good as you are. The thing is, as I said, it's not everyone's job to be a security expert. We should expect security to be part of the tools instead of expecting everyone to be a security expert. The first is possible, the second will never be.

    --
    #DeleteFacebook
  7. Remember what broke the internet... by __aaclcg7560 · · Score: 2

    The underlying problem is that too many programmers are willing to copy and paste code rather than think through what they need to code.

    Remember the left-pad crisis that broke the Internet because a developer removed his npm packages over a dispute? How hard is to write a left-pad function?

    1. Re:Remember what broke the internet... by Aighearach · · Score: 1

      Exactly. Never paste. Read the tut, understand the technique, and then apply the part you needed by typing in the correct code that you now know how to write. This way you only write your own fresh security bugs.

      OTOH, Matt's Scripts in the end were the most secure on the internet, because they'd been beaten into submission by a million trolls. Sometimes the crapware is better than the random square re-invented wheel.

    2. Re:Remember what broke the internet... by 0123456 · · Score: 2

      The underlying problem is that so much software is farmed out to Indian code-monkeys who have no idea how to program, so they just copy-and-paste whatever they find on the web. They'll have a new job in three months anyway, so why would they care that the software is crap, insecure and unsupportable?

    3. Re: Remember what broke the internet... by Brockmire · · Score: 1

      Start off your point to say "never" and finish it off with indicating WHEN it's a good idea to paste. All you guys reinventing wheels are dumb. Patch some holes, fill the tires, but don't be stupid.

    4. Re:Remember what broke the internet... by tsm_sf · · Score: 1

      The underlying problem is that too many programmers are willing to copy and paste code rather than think through what they need to code.

      The underlying problem is that we're asked to reinvent tiny wheels all day long, solving trivial problems that have been solved before by people more interested in the specific problem.

      We shouldn't be asking why people are copying bad code, we should be asking why they need to.

      --
      Literalism isn't a form of humor, it's you being irritating.
    5. Re:Remember what broke the internet... by __aaclcg7560 · · Score: 1

      They'll have a new job in three months anyway, so why would they care that the software is crap, insecure and unsupportable?

      The lead programmer (or project manager) should review the code and then beat them with a pointy stick if code was unacceptable. I'm not a professional programmer but I was a software tester for nearly seven years. The lead programmer for the developers I worked with was responsible for the quality of the code in each build. Sometimes programmers got fired if they can't do their job.

    6. Re:Remember what broke the internet... by __aaclcg7560 · · Score: 1

      We shouldn't be asking why people are copying bad code, we should be asking why they need to.

      Not sure why you're rephrasing my statement.

    7. Re:Remember what broke the internet... by Luthair · · Score: 1

      I don't think its Indians in particular, the reality is there are a lot of people in the field who 'knew computers'. You don't get to design a bridge because you know how a calculator and ruler works.

    8. Re: Remember what broke the internet... by Anonymous Coward · · Score: 0

      Because irony?

    9. Re:Remember what broke the internet... by Anonymous Coward · · Score: 0

      Remember the left-pad crisis that broke the Internet because a developer removed his npm packages over a dispute?

      This argument is silly - you're citing left-pad as an example of "copy-paste" coding, when in fact, it's the exact opposite.

      If I cut & pasted the left-pad function into my own project, then my project would have been completely unaffected by the maintainer deciding to remove his left-pad package from npm. Since I simply included that function from the javascript equivalent of a standard library, and assumed I'd always be able to download it again, the ability of J. Random Fucktard to remove his package in a fit of pique is what caused the breakage - suddenly a widely-used function from the standard library *disappeared.*

      If you had cut & pasted it into your implementation, your application would have continued working.

      This brings up several questions about the competency of app designers, but "cutting and pasting" would have actually PREVENTED this problem from occurring, not CAUSED it. The main question is this: why are you relying on downloaded, external resources without a mechanism for insulating against temporary or permanent removal of that resource? There are caching servers (nexus, artifactory, others) which will allow you to maintain a local deployable copy of that code for yourself. There are also packaging & deployment mechanisms that will allow you to bundle all of these things into a deployable bundle, rather than relying on your network and all downloadable resources to be omni-present. This goes to good, fault-tolerant design of your application.

    10. Re:Remember what broke the internet... by michael_wojcik · · Score: 1

      The underlying problem is that too many programmers are willing to copy and paste code rather than think through what they need to code.

      That's a problem; it is not the problem. Addressing it is necessary but nowhere near sufficient.

      The simple fact is that a very experienced, knowledgeable, and thoughtful developer who's simply not familiar with, say, XSS or CSRF vulnerabilities, could read, understand, and implement ideas from a tutorial that is susceptible to and fails to cover them. No amount of "think[ing] through" is going to solve that.

      It's not reasonable to expect people who haven't put considerable effort into identifying protocol vulnerabilities to rediscover XSS and CSRF. And the same goes for most other aspects of software security. At some point, even thoughtful developers will have to believe some of what they read.

  8. Re:Protect you against SQL injection? Really? by Anonymous Coward · · Score: 0

    And it's Google's fault for returning the tutorial on page one of the results. What, they're using an automated algorithm? So they need to adjust their algorithm.

  9. The real problem is tutorial poisoning by Traverman · · Score: 4, Interesting

    The important takeaway here is not that flawed tutorials lead to bad code. It's the implication that one could actually poison tutorials intentionally, perhaps in some very subtle way. While it would be quite difficult to inject malware this way (unless the tutorial convinces some idiot to download this "include file that you need for this function"), it probably wouldn't be too difficult to inject, say, buffer overflows or XSS vulnerabilities that could well be invisible to novice programmers. Those vulnerabilities could then be exploited post-deployment, perhaps using a bot scan of Github to identify broken apps that include the code. Rust is better because for something on the order of a 10% overhead vs C, it effectively eliminates buffer overflows (unless something is amiss with Rust itself, in which case we have only one bug to fix, but millions of precompiled vulnerabilities in the field). On balance, Rust seems like a net positive to security. It does nothing much, however, to prevent vulnerabilities having nothing to do with memory exploits. For that matter, one could probably write Rust code to exploit Rowhammer. Or poison a tutorial to do that. It would be completely "safe" multithreaded code... that isn't, thanks to ubiquitous shitty DRAM. There's another, subtler issue: UTF8 hacks. One could post a tutorial and substitute various characters with various similar characters. Maybe, just maybe, one could find a way to get some dufus to copy the code into his source and create an exploit because he confuses one character with another one that looks almost the same (or, even worse, exactly the same due to text rendering shortcomings on his end). On the vigilante end, I suppose the only solution is to first of all identify the poisoned/flawed tutorials, and secondly to search Github or other repositories for key snippets. This is a hard problem to automate due to the zillions of ways that the tutorial code might be imported into a project and tweaked to fit, without destroying the vulnerability it injects. So, to the noobs out there: read tutorials, but, at most, copy code from them by retyping it yourself. DON'T DOWNLOAD INCLUDES OR "REQUIRED BINARIES". DON'T CUT AND PASTE CODE INTO YOUR PROJECT. Cross-verify with multiple sources (which could have been manufactured by the same hacker, so beware similar look-and-feel), and if you still don't really understand what you're doing, then do it some other way. Now, for the public generally, I wish there were a way for us to protect ourselves from this crap. I don't think there is, apart from avoiding software like the plague. It's not like the code you cut and paste from the tutorial is going to create some obvious malware signature in most cases, especially if the tutorial is very abstract in nature. After all, there are endless versions of compilers and compiler settings in use out there.

    1. Re:The real problem is tutorial poisoning by Anonymous Coward · · Score: 1

      Someone should write a tutorial on the proper use of paragraphs.

    2. Re:The real problem is tutorial poisoning by Anonymous Coward · · Score: 0

  10. Electric swamp by fluffernutter · · Score: 1

    The internet as a whole is a tool for quick mass communication. Did people really think it would be impervious to stupidity and incompetence? Social media, news on social media.. Philosophers have long written about the effects of incorrect statements affecting humanity like ripples from a stone being thrown into a pond. They hadn't imagined a world where the pond is electric with ripples traveling outward at the speed of light.

    --
    Laws are rules for the court, but merely a bottom bar to hit for life. Think beyond laws in your actions always.
  11. Re: Protect you against SQL injection? Really? by Ronin+Developer · · Score: 1

    Whoa! Blueprints for a bridge is a very bad analogy for tutorial code. Seldom do you see certified bridge engineers cutting a pasting features of a bridge design into another another. Concept may be applied but only after due diligence.

    Similarly, unless the tutorial is on writing or securing code/services, it should only be considered an introduction to a topic or concept.

  12. Tutorials do not write bad code by yurikhan · · Score: 2

    Tutorials do not write bad code. People write bad code.

    A tutorial’s purpose is not to follow good practices in all aspects; such a tutorial would be unreadable. A good tutorial focuses on the one aspect being demonstrated, and, for the sake of exposition, intentionally neglects all other aspects, including, but not limited to, error handling, separation of responsibilities, access control, injection avoidance, naming, cache invalidation, etc.

    The implicit assumption is always that you will apply good practices that you already know from elsewhere. You get that by (a) reading books (with wider scope than just a tutorial), (b) reading war stories in blogs (where neglecting a good practice led to a horrible vulnerability or a lengthy debugging session), and (c) participating in actual real-world projects collaborating with and learning from more experienced developers.

    1. Re:Tutorials do not write bad code by Frosty+Piss · · Score: 1

      A tutorial's purpose is not to follow good practices in all aspects; such a tutorial would be unreadable.

      Really?

      --
      If you want news from today, you have to come back tomorrow.
    2. Re:Tutorials do not write bad code by yurikhan · · Score: 1

      Imagine you’re writing a tutorial on, I don’t know, getting a list of repositories in a GitHub account and dumping their names and descriptions to the terminal. At the core, it is a single HTTP request: GET /users/:username/repos. You could probably trim the whole thing down to a shell one-liner.

      But no, you want good practices. Let’s do it.

      Our script will accept a user name and a configuration option for the API endpoint; that means some CLI argument parsing and --help handling. Check that the API root is a valid IRI. Validate and/or escape the user name for use in a URL. Handle DNS resolution errors. Handle TCP connection errors. Handle timeouts. Check if the HTTPS certificate presented by the alleged GitHub is well-formed, signed by a trusted CA, strong enough, valid for key exchange, valid at this point in time. Constant vigilance! Send the request. Check that the first line of the response is valid as an HTTP status line. Handle redirects. Not that there are any in the normal case, but you can never be sure! Be careful to not get stuck in infinite redirects. Check that the final status code is 200. Check that Content-Type is application/json (case-insensitively, after trimming any whitespace where allowed by HTTP spec and ignoring any unknown MIME type parameters). Parse the response, handle any UTF-8 decoding errors, handle any JSON parsing errors. Validate the parsed response against JSON Schema, handle any validation errors. Do not forget to sanitize the name and description against possibly malicious terminal control sequences before printing! Be sure to return a zero exit code in case of success and a non-zero in case of any error.

      What was that tutorial about again?

    3. Re: Tutorials do not write bad code by Anonymous Coward · · Score: 0

      No wonder people make so many mistakes programming. We have built a glass house and are starting to realize that little pebbles chip the glass and slowly cause it to break.

  13. I alluded to all of this yesterday... apk by Anonymous Coward · · Score: 0, Interesting

    See subject & this post - Especially regarding "code sharing" (plagiarism) that backfires for security https://developers.slashdot.or... and yes, it takes away the "mental exercise" of doing it yourself that makes you stronger.

    APK

    P.S.=> It's not the greatest idea doing "opensores" (Chrome EFast is my evidence here) or "codesharing" per the above... apk

  14. In a world by CptLoRes · · Score: 2

    where supposedly anyone can 'code', this is the expected result. Why would you expect anything else from cheap inexperienced labor?

    1. Re:In a world by Frosty+Piss · · Score: 1

      where supposedly anyone can 'code', this is the expected result. Why would you expect anything else from cheap inexperienced labor?

      There is a "coding" school here in Seattle (I think it's some chain) that will teach you to "code" in 7 or 8 weeks, and then apparently get a $70k job.

      I don't believe it, I think they are designed to suck up GI Bill money from veterans.

      But at least they are teaching Python...

      --
      If you want news from today, you have to come back tomorrow.
  15. Hardly the tutorials fault by wisnoskij · · Score: 2

    Hardly the tutorials fault. A tutorial will not cover every edge case of your specific example. It will not spend 90% of its length teaching about only partially related topics. I read the same SQL and HTML GET tutorials as everyone else, and a basic understanding of programming I learned in the first month of grade 9 prepared me for sanitizing the input. SQL, isn't special, and GET is no different than CIN, it's not rocket science.

    --
    Troll is not a replacement for I disagree.
    1. Re:Hardly the tutorials fault by Anonymous Coward · · Score: 0

      I would agree - but if a tutorial is teaching how to use a database access layer, and isn't teaching you to use bind variables, then it absolutely is at fault.

      In fact, even if it's not specifically teaching database stuff, but includes some database code that uses concatenation instead of parametization, then it's still absolutely at fault. There is no excuse for SQL injection. None. It shouldn't even enter into someone's head to use concatenation. Parametized queries with bind values is the ONLY way to do it.

  16. Re:Protect you against SQL injection? Really? by ilctoh · · Score: 1

    That's the problem - In your analogy, you've hired "production workers" when you actually need engineers.
    If you're hiring people dumb enough to copy and paste code into production, without understanding the ramifications, you deserve what you get.

    --
    How many slashes would a slashdot dot, if a slashdot could dot slashes?
  17. I keep b*+hing about cloud computing by TheOuterLinux · · Score: 0, Redundant

    So, I know how everyone feels. If something goes bad code wise, it goes bad for all of us, whether we update or not thanks to a thousand apps running the same single API. Open source used to destroy open source only to kill the desktop because they can't invent a new architecture fast enough to sell new computers. And, the new ones now aren't that much different, if not less powerful than the ones five years ago. So, the Google and Window$ come up with as many apps that need Internet to work as they can to lock you into their bs. And now, Mark Shuttleworth wants to focus on cloud computing for Ubuntu as well. They're killing the desktop and money is the only reason. More problems from bad code means more money to fix or replace computers. I like how they say things like open source to describe their server based software. Ok, but what good does that do for the average person? Do we all buy our own servers? Companies using open source to destroy privacy and control on desktops and AI to destroy encryption. That's the future.

  18. Insecurity from the bottom up. by Gravis+Zero · · Score: 2

    While bad tutorials help make shitty coders, there will always be shitty coders. The question is then becomes, "how do we protect internet servers from shitty code?" The answer to this is with secure interfaces and we've failed at most levels.

    Let's start at the top with web serving daemons. Web serving daemons (e.g. Apache) currently support script languages (e.g. PHP) which are a minefield of insecurity. The fact that they were happy to enable script language interpreters and execute them with the same level of privilege as the web serving daemon itself (by default at least) use without a second thought shows a lack of understanding about the dangers they hold.

    The next level of insecurity is in the script language interpreters which are being invoked by the web serving daemons. Script language interpreters intended for use with web servers have only "recently" added the ability to restrict certain operations. However by default, even the most dangerous operations like the execution of text strings are enabled. The most egregious flaw I've seen is in PHP which allows ability to define the value of variables that are not explicitly requested. At no point was this a good idea.

    Drilling down, we get to database daemons. Database daemons do not promote the use of a function call based interface but rather a text only interface. Frankly, anything goes with a text based interface which leaves it wide open to naughty inputs. A text interface is a wonderful concept for ease of use but it's just terrible for security.

    I know that it's the shitty coders fault for writing shitty code but a defensive approach to design is something we should strive for to increase our level of security.

    --
    Anons need not reply. Questions end with a question mark.
    1. Re:Insecurity from the bottom up. by joboss · · Score: 1

      Honestly PHP has been pretty good for security if you use the proper manual and actually read it properly. It has a lot of pitfalls but most are detailed in the manual. Unfortunately few people really RTFM or care *how* what they are doing works too much as opposed to that it works. In any language that's a problem.

    2. Re:Insecurity from the bottom up. by Gravis+Zero · · Score: 1

      It has a lot of pitfalls but most are detailed in the manual. Unfortunately few people really RTFM or care *how* what they are doing works too much as opposed to that it works. In any language that's a problem.

      It's a significantly larger problem for script languages rather than compiled languages.

      --
      Anons need not reply. Questions end with a question mark.
  19. Re: Protect you against SQL injection? Really? by Brockmire · · Score: 1

    Is the salary for online free tutorial writer in the same ballpark as bridge engineer? Someone should tell these open source not to release anything unless it's perfect, either.

  20. Why won't developers use the real documentation? by jtara · · Score: 1

    I don't get it why some many developers WON'T use the real documentation. Heck, many of them WON'T even download from official sources, instead relying on third-party collections with obsolete versions, or, worse (at least potentially) intentionally hacked/poisoned mods.

    WHY do so many use W3Fools? I once had a Google filter set-up to keep them out of search results. But W3Fools gamed Google with dozens or hundreds of of different domains, until the technique became widespread and Google threw in the towel and removed the filter feature. W3Fools is the WORST possible place to get accurate information. I half-suspect it is actually a Russian or Chinese initiative to spread absolute crap all over the Internet. Find out where W3Fools is blocked. That will tell you who is behind it! ;)

    MDN is a GREAT site for learning HTML/CSS/JS. The jQuery Learning Center is a GREAT site for learning jQuery. Why do so many flock to tutorial sites with horrible quality and WRONG information?

    I don't use PHP, so don't know if the official documentation is GREAT. I have to guess, though, that after all these years, it can't be totally awful.

    (Last time I used PHP was like a year after it first appeared. I think I had it emailed to me by the author. I feel for the author, who is probably blamed by many for it's failings. It was just a simple script to help him with his blog site, and he was an amateur. I do not mean "amateur" in a disparaging way, I mean it in a descriptive, literal sense. Others took it up and built crap on top of a simple script with a simple purpose. Along the way, there's been a corrective course that turned it into a language with a not-completely-awful syntax, but the developers haven't had the will to remove the awful parts. It seems impossible to get PHP developers to stop cutting-and-pasting, and to stop using the awful parts.)

    CODE DOES NOT BELONG IN HTML TEMPLATES. CODE DOES NOT BELONG IN HTML TEMPLATES! CODE DOES NOT...

    Unfortunately, that's how MOST PHP sites are written.

  21. Good job by Anonymous Coward · · Score: 0

    Millennials, who refuse to do anything the traditional way. This won't be the only time in life it comes back to bite you on the buttocks. Ironic that your helicoptor parents did such a crappy job of teaching you anything given how omnipresent they were (are), huh?

  22. Re:Why won't developers use the real documentation by phantomfive · · Score: 1

    I don't get it why some many developers WON'T use the real documentation

    Because reading documentation is a skill many of them have not developed yet.

    --
    "First they came for the slanderers and i said nothing."
  23. Bad code can come from bad teachers by Anonymous Coward · · Score: 0

    Had a room-mate learning to code. They got some code from their college course as

    char inchar;
    while( (inchar = fgetc(ifile)) != -1) { .... }

  24. Re: Protect you against SQL injection? Really? by __aaclcg7560 · · Score: 1

    Seldom do you see certified bridge engineers cutting a pasting features of a bridge design into another another.

    I'm not so sure about that. I worked a few years in construction with my father. He examined the blueprints for every project carefully to order his list of materials and occasionally finds minor mistakes that he need to correct on the ground. One day he found a three-foot wide mistake between two pages of the blueprint for the same wall. The architect called bullshit because the two pages line up perfectly with each other. So my father had the architect and main contractor walk the layout on the ground for the foundation before it got poured. Lo and behold, a three-foot wide gap was found that prevented the wall from lining up. That problem was in the blueprint and not how the foundation guys laid the layout, although the main contractor yelled at them for not catching the mistake soon.

  25. Software Constipation? How Cute by LifesABeach · · Score: 1

    I find it amazing that those that are the most efficient, cannot create worth a damn. Maybe a demonstration of bleeding edge software design in some field few even understand, like maybe human neural patterns? Of course, googling would only be a suggestion.

  26. Becone enginnering ? by Anonymous Coward · · Score: 0

    Decades old question: should programming become an engineering level profession?

    1. Re:Becone enginnering ? by Anonymous Coward · · Score: 0

      Decades old question: should programming become an engineering level profession?

      If somebody can die when the programmer fucks up then yes, otherwise no.

  27. Re:Why won't developers use the real documentation by Anonymous Coward · · Score: 0

    And dogma will eat your homework.

  28. PHP and MySQL? by PJ6 · · Score: 1

    No other explanation is needed. Why bother blaming bad tutorials?

  29. Internet-era fake programmers by Anonymous Coward · · Score: 0

    Instead of actually being COMPETENT, we now have armies of phoney coders who know little about what they are doing because all they're really doing is pasting together lots of blobs of crappy code they found on the internet.

    Any business employing these fake programmers deserves all the badness that comes later when their junk collapses and the fake programmers are unable to fix it because they never fully understood how it sortof worked since they never actually wrote most of it.

    Before the internet, this particular problem did not really exist.

    Hey, you kids, GIT OFFA MY LAWN! (or at least learn to actually write and understand your own code)

  30. Re:Why won't developers use the real documentation by Anonymous Coward · · Score: 0

    Ideally they should study the real documentation on the company's paid training time. Learn the thing from ground up. Solve problems using both knowledge and critical thinking.

    In reality they're shouted down by the boss: "GET THIS WORKING RIGHT NOW I DON'T CARE FUCKING HOW YOU CODE MONKEY!!!!"

  31. Good sources by joboss · · Score: 1

    I've been teaching people about this for ages. I have reviewed perhaps a couple hundred recruitment tests as well. You would be shocked how many can't even indent and you see injections all the time. I sometimes perfect to see manual escaping using the provided functions than prepared queries because prepared hides the problem. I am pretty sure a lot of them use tutorials as they are doing the test and it makes me wonder.

    When I am training juniors one of the first thing I get them to do is to learn to go straight to the authoritive manual and ignore the top results. I explain to them how SEO works and that these people are making money sometimes practically plagiarising the manual and then using SEO to get their ad laden version to the top. Originally it came from having for some languages bad manuals or really thick specifications (W3C never wrote decent manuals). They get a bit of traction being one site for multiple languages as well.

    It's not just tutorials but also questions (common error messages, problems, etc). Stack overflow has done a really good job of cleaning things up. I still see junk in there rarely but you can at least add your piece. One of the worst cases I saw was when I searched for best MySQL practices and found a guide with some questionable things or poor explanations. The result of that is that I had one developer adding LIMIT 1 to the end of a hundred queries entirely needlessly. This practice added noise to code and led to obscuring possible errors (where if you don't get zero or one result the query is broken). It was never added in the kind of situation you would actually want to limit by one such as with an order by to get the top result. These practices are useless if someone doesn't actually understand what is going on and if they understand that it should be immediately obvious when and when not to limit. That was one of many dodgy things in there. I think the worst has to be where if you downloaded something precompiled for a certain platform you would get an error message about having the wrong library version (dynamic linker error). The guide explained how to hex edit it to look for a different version. Asides from the potential issues this can cause with compatibility and segfaults (security as well), the software was open source so could have been downloaded and recompiled.

  32. NPM : no standard library ? by DrYak · · Score: 1

    The underlying problem is that too many programmers are willing to copy and paste code rather than think through what they need to code.
    Remember the left-pad crisis that broke the Internet because a developer removed his npm packages over a dispute? How hard is to write a left-pad function?

    Sorry but now.

    You should not be copy-pasting a left pad function.
    But, you should not be re-implementing yet another one yourself neither.

    Simple trivial task like this *should go into a standard library*.

    On any machine on which I fire up a C compiler, I know that at least I can rely on a decent compliant standard library for simple task.
    If I want to left-pad a number, I just give the appropriate parameter to printf.
    (Well unless I'm writing kernel code, or unless I'm writing for an tiny embed platform where every byte counts and I need as specific code as possible).

    Why does Npm needs to be any different ?

    ---

    Also, left-padding function might be not as trivial as you think. Not every language is english, not every language is written only with the ASCII subset of unicode. Some weird corner cases will start to popup. Think situation where : Number of bytes IS NOT number of unicode code point which in turn IS NOT the number of displayed characters (e.g.: some of the unicode are diacritics or other such modifiers)
    (To think about worste case scenarios: How do you even left-pad Zalgo ?)
    But these are indeed extreme cases.

    --
    "Sufficiently advanced satire is indistinguishable from reality." - [Tips: 1DrYakQDKCQ6y52z6QbnkxHXAocMZJE61o ]
    1. Re:NPM : no standard library ? by __aaclcg7560 · · Score: 1

      Why does Npm needs to be any different ?

      Npm is the Node.js Package Manager. Many JavaScript programmers who don't use Node.js directly in their own projects will use npm for the JavaScript tool chain environment. I use JavaScript sparingly in my own projects so I'm not that familiar with the language. I'm under the impression that JavaScript doesn't have a standard library outside of its core functionality, but it does have a ton of frameworks available.

  33. Copypaste vs reimplement vs standard library by DrYak · · Score: 1

    We shouldn't be asking why people are copying bad code, we should be asking why they need to.

    Not sure why you're rephrasing my statement.

    There's a subtle difference.

    Your statement clearly poses re-implementation of code as the main alternative to copy-pasting. (boils down to "You should intelligently re-implement, instead of blindy copy-pasting").

    The above statement simply discourages from copy-pasting (boils down to "Do not copy-paste, why do you even want to ?") but is still open to *any* solution :
    that includes having a standard library (which was another criticism back during the "#LeftPadGate" ) which is also a valid solution : if there a decent standard library, nobody will need to copy-paste anymore either (but nobody will neither need to re-implement).

    --
    "Sufficiently advanced satire is indistinguishable from reality." - [Tips: 1DrYakQDKCQ6y52z6QbnkxHXAocMZJE61o ]
  34. Problem across the board by Martin+S. · · Score: 1

    I find the majority of online tutorials are very naive with regard to development best practice and stack-overflow is one of the worst offenders for perpetuation this problem. It is a vicious circle. Simplistic solutions get upvoted while better answers take longer to prepare and comprehended by fewer people.

    It is common to see answers presented than ignore the bigger picture, for example, a poor separation of concerns and high levels of coupling are the norm.

    If you call this out your answer will often be downvoted or challenged based on the evidence from simple tutorials or that some-one has been gaming stack-overflow. While evidence such as being a Portland Pattern repository at C2 is ignored our outright dismissed.

    Other tech areas that exhibit the same problem is Cucumber BDD (first person pronouns are endemic anti-pattern) and Selenium WebDriver tutorials, using highly qualified locators and conflating representation with the test code.

    When you need to continuously re-coach development best practices to teams as a automation consultant it can get very tiresome very quickly.

  35. Cause and symptom by Anonymous Coward · · Score: 0

    The copy-pasta "cause" is obvious, but the existence of the flaws and their propogation are symptomatic of a complex subject matter (ie domain, functionality, design, and/or API).

  36. Say it ain't so by Anonymous Coward · · Score: 0

    What? You mean if you teach someone to write vulnerable code, they then tend to write vulnerable code? Get outa here! Whodathunkit? I hope they didn't spend too much on this "study."

  37. Re: Why won't developers use the real documentatio by Anonymous Coward · · Score: 0

    "Find out where W3Fools is blocked. That will tell you who is behind it!"
    Well, since you admit blocking it....

  38. Re:Protect you against SQL injection? Really? by Zephyn · · Score: 1

    And it's Google's fault for returning the tutorial on page one of the results. What, they're using an automated algorithm? So they need to adjust their algorithm.

    Or ask for support from wherever they copied it.

  39. Standard library by DrYak · · Score: 1

    I'm under the impression that JavaScript doesn't have a standard library outside of its core functionality, but it does have a ton of frameworks available.

    Yup, that's exactly my (poorly worded) complain.
    Tons of semi-usefull frameworks everywhere,
    but not a basic library of standard functions.

    Leading to either tons of copy-pasting, or relying on scattered external modules.

    --
    "Sufficiently advanced satire is indistinguishable from reality." - [Tips: 1DrYakQDKCQ6y52z6QbnkxHXAocMZJE61o ]
  40. motherfuckers don't document APIs for shit. by Anonymous Coward · · Score: 0

    Instead of actually being COMPETENT, we now have armies of phoney coders who know little about what they are doing because all they're really doing is pasting together lots of blobs of crappy code they found on the internet.

    Any business employing these fake programmers deserves all the badness that comes later when their junk collapses and the fake programmers are unable to fix it because they never fully understood how it sortof worked since they never actually wrote most of it.

    Before the internet, this particular problem did not really exist.

    Hey, you kids, GIT OFFA MY LAWN! (or at least learn to actually write and understand your own code)

    Maybe if motherfuckers writing APIs would fucking document their shit like they did back in the days of "Real Programmers", that wouldn't be a problem.

  41. Re: Protect you against SQL injection? Really? by Anonymous Coward · · Score: 0

    It's the developer's fault for copy pasting. it's management's fault for under-hiring or hiring poorly, or not having a full time security analyst. it's Google's fault for not checking all online code tutorials for security bugs, and for that matter everybody's web site for the same bugs. It's the attacker's fault for being evil. Let's not leave out the media, president Whoever, the Russians, and ISIS. Actually it's all my fault, I'm dreaming all of this.