default

How to stop SQL injection attacks

If you have a website which is powered by a database it is potentially vulnerable to SQL injection attacks – this is relatively simple to protect against and the risks of not doing so are to compromise the integrity of the data stored on your server and possibly the website itself.

What is an SQL Injection attack?

Most websites will pass data from one page to another in order to maintain continuity. For example you might be looking at a list of products and you click on a particular product for more information. The website will pass the ID of the product in question to the next page so that it know what informationt o serve to the customer.

In many cases this is passed in the URL, so you might have  something like www.examplewebsite.com/propduct?id=xyz

An SQL Injection attack occurs when the recipient page takes the XYZ in the URL and makes a query with the database without verifying first that it doesn’t contain any additional and unexpected nasties.

How do I stop Injection attacks?

The key is that every time you retrieve a variable which you intend on passing to the database, check that it is in the expected format. Usually a product ID would be numeric, and not include any other characters. A date might be in the dd/mm/yyyy format. Once you have predetermined what format you expect each variable to be in, create a rule to check it prior to submitting it to the database – and if it fails stop the process.

I know what format I expect it to be in, but how do I check it?

The PHP code preg_match is probably the best method as it allows you very specific controls.

The following would check the variable $input for a date in the format yyyy-mm-dd. If there are any other characters, the page would be redirected to a page where no database queries are made, so stopping the threat.

if (!preg_match(‘/^[\-+]?[0-9]*\-?[0-9]*\-?[0-9]+$/’, $input)) {
header(“Location: http://www.examplewebsite.com/404redirect.php);
exit;
}

The following test just allows numeric characters, any number of them, but anything else kicks it out:

if (!preg_match(‘/^[\-+]?[0-9]+$/’, $input))

You can also allow alphabetical characters, in the following case any character in either upper or lower case:

if (!preg_match(‘/^[\-+]?[a-zA-Z]*+$/’, $input))

There are plenty of guides on the Internet about how to use preg-match()

Simplify the process

You will probably find that you use one or two formats a lot, so create a function where you pass the variable and the type of format expected, then each time you retrieve a variable run it through your function to verify it is of the expected format.

 

 

 

default

Networking groups

Last year I became involved with the Homeworking Alliance, a networking group for homeworkers.

At the time it had only recently been founded and was being run on a voluntary basis by Jane Giffard-Tiney. It’s now  been put on a more professional footing and is expanding, with groups in Lutterworth, Kettering and I think Leicester all pending.

Within Market Harborough there are A LOT of networking groups, but the majority of them suffer from the same obstacles to me joining – the first and biggest is that they meet for breakfast once a week or every other week from 7-9 am. As I’m responsible for the getting the kids off to school and nursery that is a non-starter.

They also invariably insist on only one person per industry joining, so they’ll have one accountant, one lawyer etc etc. The idea is that all members are constantly on the lookout for referals for other members of the group and they don’t want any conflict of interest.

From a business perspective I can see this being potentially rewarding – you turn up to a meeting of 10-15 people and each of them is supposed to give you a business lead each week (although you have to return the favour), so I would consider doing it if I could, but personally I think it is short-sighted – I am not sure that I would be able to provide leads for all those other members each and every week so likewise you have to question whether the quality of leads received would be any good; in addition I would prefer to compete with other companies on an equal footing,  if there is another company doing what I do and they can offer a better or cheaper service to a customer then good luck to them.

Besides the Homeworking Alliance I am also a member of the Market Harborough Chamber of Commerce, (which tends to meet 7-9 pm) which is also very good. Both groups are informal and friendly and both have provided me with business leads.

default

auto-responder – the saga continues!

Aggrr..

I set up my autoresponder as per previous posts, everything worked a charm until… my email client decided to start downloading all previously downloaded emails – it didn’t actually get that far as two days later it was still calculating the size of the download.

Either way, I had two days worth of emails not downloaded and therefore not responded to. There must be a more foolproof system than this?!

Other than that, the everything else worked a charm..

default

Groundwire softphone

We went to Marrakech in Morocco during half term – I was on call and had checked with 02 prior to leaving that my phone would work, which apparently it would albeit at a cost: 81p a minute to call the UK and 50 something pence a minute to receive calls.

The plan however was to use Groundwire, which is a ‘softphone’, i.e. a software based phone using Voice Over IP to make and receive calls, rather than using the 02 network. You need a VOIP account to use groundwire and I was using my  Globe2 account – this costs just 1.5p a minute to make calls and nothing to receive.

Once in Marrakech I was very pleased to have this functionality, not just because of the cost but because I had zero signal the entire time I was there! In hindsight I think if I’d rebooted my phone it might have connected.

The only issue then was accessing the Internet, as Maarrakech isn’t the most digital place you’ve ever been to. Initially we managed to find an Internet cafe with an unsecure wifi connection, so we stood in the street (which was very noisy with motorbikes, donkeys, cyclists, pedestrians and cars all trying to squeeze through a narrow single lane space) but eventually found out that if we stood in a specific spot in our Riad (hotel) we could get a connection in piece and quiet – and like this it worked a charm, I had a few issues I had to deal with but still managed to enjoy my time away.

Groundwire is for the iPhone and is OK, the call quality was absolutely fine but I find it a bit clunky receiving calls. Jo’s Blackberry uses a different softphone which seems a lot more intuitive, I’ll be posting a review on this soon on Globe2 (along with a new site soon!)

default

new-look twitter

Is it me or is this not working?
I tried it in both Firefox and IE but all I get is a header bar with a blank page. IE brings up page errors:

default

auto-responder update

This is the first time I’ve had to set my auto-responder since last time, the biggest problem I see is how not to get stuck in the auto-responder loop.

I’ve been through the emails I get and have a more comprehensive list of generic emails not to reply to:

  • no-reply
  • noreply
  • do-not-reply
  • my own domain name
  • news
  • money
  • mailing
  • linkedin
  • amazon
  • notification
  • service
  • newsletter
  • auto
  • support
  • webmaster
  • publish
  • contact
  • customer
  • purchase
  • welcome
  • security
  • magazine

You may also need to add in specific companies – I’ve got amazon and linkedin in my list above – which are relevant to you.

The idea is that I have a message rule above my autoresponder which says ‘if I receive an email which includes any of the following in the Sender field, stop processing more rules’. Then if I get a newsletter from someone I don’t auto-respond to it, they don’t respond to my autoresponse, etc.

I’ll let you know if I have any more luck with my ammended rules!

default

WordPress: switch between subfolder and subdomain for blogs

I set up a new wordpress/buddypress site and managed to select the option which creates new blogs as subdomains rather than subdirectories, which was what I wanted. Having done this some time ago I knew there was a simple way to switch between the two but a thorough search of forums etc suggested that a complete re-install was required, but this is not the case.

To switch the setting is very simple: edit the following line in wp-config:
define(‘VHOST’, ‘no’);
The above line is currently set to NOT use subdomains. Changing it to ‘yes’ switches the setting so that new blogs are created as a subdomain.

CATCH
There is one catch: this works fine if you haven’t already created any blogs, but will cause problems for any existing blogs.

default

Which WordPress e-commerce plugin?

I’ve had a few customers come to me looking for a website to display their products. Their budgets did not really warrant a custom built e-commerce site so I took a look at whether a customised WordPress site might be able to offer them what they wanted within their budget.

My first attempt was with wp-e-commerce, which seems to be widely supported in the respect that there are a number of additional plugins to go with it and a lot of downloads of the plugin – but it did not work for me. It just all seemed pretty buggy and the final straw was that I could not for the life of me find a way of accessing the basket once I’d selected products to buy. I think it may have had something to do with the Theme I was using but either way, a quick and simple solution it wasn’t.

Next up was Zingiri which seemed more stable and I thought it might do the trick, but then I found that the upload product image button did nothing so I had no way of uploading images to go with the products. I tried looking at their demo site but the interface was different to the one I had in my installation so I couldn’t compare – again I gave up.

My last and final attempt was WpStoreCart which seems to do the job nicely. Nothing too fancy, a pretty easy setup process which allows you to select the currency etc and a checkout to Paypal all setup.  I setup a demo site for my prospective customers to take a look, it took me probably a couple of hours if you exclude the messing about with the other plugins initially.

Tags:
default

Sage, Journal entries and director loans

Despite having an accountant I decided that I wanted more visibility of my accounts and to that end I bought a copy of Sage version 16.

I’ve had a few moments where I’ve struggled but most of it is intuitive. The one area that I have found repeatedly difficult is how to use journal entries when accounting for movements in and out of my director loan nominal account – as the credit and debit columns do not necessarily work as I immediately thought they would.

The journal entries need to balance out, so a movement from one account is replicated with a counter movement to another account – double entry book keeping.

The following examples may help anyone else struggling with this:

LOAN REPAYMENT
If I am reducing my director loan account, so in effect a payment is being made from my business bank account into my personal bank account I enter the following information:

N/C Name Details T/C Debit Credit
2101 Director Loan Account loan repayment T9 140.00 0.00
1200 Bank Account loan repayment T9 0.00 140.00

The N/C values are those used by default in Sage, yours may differ. The T/C value should always be set to T9 as this is VAT exempt.

This will result in the Director Loan Account being reduced by 140 and a payment out of the business bank account for 140. The fact that it says 140 in the business bank account Credit column is confusing as it is the opposite of what happens.

INCREASE IN DIRECTOR LOAN
If I am increasing my director loan account, so in effect a payment is being made to my business bank account from my personal bank account I enter the following information:

N/C Name Details T/C Debit Credit
2101 Director Loan Account loan T9 0.00 140.00
1200 Bank Account loan T9 140.00 0.00

This will result in the Director Loan Account being increased by 140 and a payment into the business bank account for 140. Again, the 140 in the Debit column for the bank account is the opposite of what happens.

default

common autoresponder mistakes

Setting up an autoresponder for your emails for when you are away is relatively well documented but there are some additional things you need to do to ensure it works as you plan, otherwise you can get caught out.

1. The autoresponder loop

If you setup an autoresponder to simply reply to any incoming email with a ‘I’m away email’ then you can get caught in a loop if the sender has setup a similar autoresponder. i.e. I received an email from ebay, to which my autoresponder replied to say I was away, to which ebay replied that ‘my message was important to them’ or somesuch, to which my autoresponder replied to say I was away to which … you get the idea. I had set up various filters etc to keep my emails to the minimum so I could pick them up remotely on my iphone, where I was paying according to the volume downloaded. This loop generated an email about every other minute until I was ironically rescued from drowning in auto emails by:

2. The automatic update

If you forget to switch it off, Windows will automatically check for updates and install them, if that means a restart then your emails are no longer checked and the autoresponder doesn’t kick in.

These two both caught me out but a third which I DID manage to do but which I don’t see often mentioned is to ensure that your computer is set not to sleep after a certain amount of time.

Solutions:
1. It is unfortunately difficult to make this 100% foolproof as not all autoresponders reply with a copy of your original email, so you can’t simply check for a word used in your original email to stop the process. My best effort would be to create a rule which sits above your autoresponder, which checks for :
- a word (such as ‘autoresponder’ or whatever you have used in your reply)
- certain give-away addresses, such as ‘donotreply@’, ‘blackhole@’ etc
- any domains which you happen to know of which has this kind of receipt notification set up

If any of the above are found stop the system from processing any more rules, so it never reaches your autorresponse rule.

2. stop the computer from updating

Go to : control panel > system and security > windows update > change settings.

Change important updates to: anything except install automatically.

Note that this does pose a minor security risk but you can’t have your cake and eat it, just remember to turn it back on when you return.

3. stop the computer from sleeping

Go to : control panel > hardware and sound > power options > edit plan settings.

Change put the computer to sleep: never

These settings in 2 and 3 are for Windows 7.

© dougandrews.co.uk
CyberChimps