Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Regular Expression to check for Oracle reserved words and special characters & sql injection attacks

Regular Expression to check for Oracle reserved words and special characters & sql injection attacks

Scheduled Pinned Locked Moved C#
databaseoracleregexhelpquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 2970611
    wrote on last edited by
    #1

    Hi I have searched the internet and I have been able to find a regular expression that stops users from inputting into a text box words that Oracle uses as reserved words, or characters that it considers special to it unless they are enclosed in quotes along with a regular expression that detects sql injection attacks. Can anyone help?

    B G P 3 Replies Last reply
    0
    • U User 2970611

      Hi I have searched the internet and I have been able to find a regular expression that stops users from inputting into a text box words that Oracle uses as reserved words, or characters that it considers special to it unless they are enclosed in quotes along with a regular expression that detects sql injection attacks. Can anyone help?

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      Use parameterised queries, unless there is a good reason not to. If there is a good reason not to, escape input on the server side when making up the query. Validating input fields in this way is one of the worst ways to prevent attacks (because it stops users entering legitimate information).

      U 1 Reply Last reply
      0
      • B BobJanova

        Use parameterised queries, unless there is a good reason not to. If there is a good reason not to, escape input on the server side when making up the query. Validating input fields in this way is one of the worst ways to prevent attacks (because it stops users entering legitimate information).

        U Offline
        U Offline
        User 2970611
        wrote on last edited by
        #3

        We are in a way undertaking a parameterised queries. I am actually building a query tool in wpf and restricting what sort of queries a user can run. All I am trying to do is where a user sets a constraint, such name like = 'Bob', that they cannot enter a reserved word or use it to launch an attack. This is why I am looking for a regular expression!

        B 1 Reply Last reply
        0
        • U User 2970611

          Hi I have searched the internet and I have been able to find a regular expression that stops users from inputting into a text box words that Oracle uses as reserved words, or characters that it considers special to it unless they are enclosed in quotes along with a regular expression that detects sql injection attacks. Can anyone help?

          G Offline
          G Offline
          GuyThiebaut
          wrote on last edited by
          #4

          If you are using PHP at the front end this is a very helpful tutorial: Clickety[^] The generally accepted advice is to escape non alphanumeric characters in text entry boxes and

          mysql_real_escape_string()

          should do the job for you if it is PHP at the front end...

          Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
          U 1 Reply Last reply
          0
          • G GuyThiebaut

            If you are using PHP at the front end this is a very helpful tutorial: Clickety[^] The generally accepted advice is to escape non alphanumeric characters in text entry boxes and

            mysql_real_escape_string()

            should do the job for you if it is PHP at the front end...

            Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
            U Offline
            U Offline
            User 2970611
            wrote on last edited by
            #5

            It is WPF or windows presentation foundation in c# with an Oracle 10g database not php and mysql

            G 1 Reply Last reply
            0
            • U User 2970611

              Hi I have searched the internet and I have been able to find a regular expression that stops users from inputting into a text box words that Oracle uses as reserved words, or characters that it considers special to it unless they are enclosed in quotes along with a regular expression that detects sql injection attacks. Can anyone help?

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              One of the problems will be having to keep it up to date. Something that's easy to do is to see if the string contains multiple statements separated by semi-colons; see my LibSql.SplitSqlStatements method in here[^].

              1 Reply Last reply
              0
              • U User 2970611

                It is WPF or windows presentation foundation in c# with an Oracle 10g database not php and mysql

                G Offline
                G Offline
                GuyThiebaut
                wrote on last edited by
                #7

                Check this out: oracle_sql_injection_attacks[^] It is also the responsibility of the DBA to ensure that, whatever you pass in to Oracle, you are not able to create an injection attack - so talk this over with the DBA too.

                Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
                U 1 Reply Last reply
                0
                • U User 2970611

                  We are in a way undertaking a parameterised queries. I am actually building a query tool in wpf and restricting what sort of queries a user can run. All I am trying to do is where a user sets a constraint, such name like = 'Bob', that they cannot enter a reserved word or use it to launch an attack. This is why I am looking for a regular expression!

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #8

                  But what if the user's name includes a banned character (e.g. O'Donnell)? I'm sure there are a few people with surnames that are database reserved words, too. This is why you should escape whatever is passed to you so it isn't an injection string, not 'validate' in such a way that legitimate user input is excluded. Producing a safe SQL string is relatively easy if what you're escaping is always going to be a quoted parameter, you need to escape quotes, and a good idea to do semicolons for paranoia too.

                  1 Reply Last reply
                  0
                  • G GuyThiebaut

                    Check this out: oracle_sql_injection_attacks[^] It is also the responsibility of the DBA to ensure that, whatever you pass in to Oracle, you are not able to create an injection attack - so talk this over with the DBA too.

                    Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
                    U Offline
                    U Offline
                    User 2970611
                    wrote on last edited by
                    #9

                    We have already done this, but what we are doing is creating a query tool that runs against a query database that is copy of the main database. The users queries run against some views, because the users can create any number of combination of queries against these views it is not possible to binding or any of the usual stuff. Therefore, we have to be as flexible as possible. We control what they can select on and join on with the views but we cannot control their constraints such "name Like "Bob". Therefore, it is imperative for me to have away of stopping "Bob; 'DROP TABLE'" type situations.

                    G 1 Reply Last reply
                    0
                    • U User 2970611

                      We have already done this, but what we are doing is creating a query tool that runs against a query database that is copy of the main database. The users queries run against some views, because the users can create any number of combination of queries against these views it is not possible to binding or any of the usual stuff. Therefore, we have to be as flexible as possible. We control what they can select on and join on with the views but we cannot control their constraints such "name Like "Bob". Therefore, it is imperative for me to have away of stopping "Bob; 'DROP TABLE'" type situations.

                      G Offline
                      G Offline
                      GuyThiebaut
                      wrote on last edited by
                      #10

                      Hi, Just wanted to let you know that it is not me down-voting you comments. I hope you find a solution, when you do let us know :)

                      Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups