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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to prevent running javascript code from address bar

How to prevent running javascript code from address bar

Scheduled Pinned Locked Moved ASP.NET
tutorialcsharpjavascriptasp-nethelp
12 Posts 5 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.
  • A Ahmad Safwat

    Hi guys, I need a help please In my asp.net 2 pages, when I disable some controls on page, user can run some javascript code in address bar that enables my disabled controls, that will cause un-needed results for example A gridview that lists exams with a checkbox for each exam, when at least one student has launched an exam, I disable its checkbox so that instructor cannot delete it Now how can I prevent user from running javascript code from address bar to enable that checkbox, then delete exam

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #2

    You should NEVER rely on javascript for anything. You CANNOT disable it. Anything that is selected via javascript, MUST be validated on the server side before performing any actions.

    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

    N 1 Reply Last reply
    0
    • C Christian Graus

      You should NEVER rely on javascript for anything. You CANNOT disable it. Anything that is selected via javascript, MUST be validated on the server side before performing any actions.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #3

      Christian Graus wrote:

      You CANNOT disable it. Anything that is selected via javascript, MUST be validated on the server side before performing any actions.

      Then what will be the use of javascript if we are rechecking everything in server before processing ? Or is it possible to identify javascript is supported by the browser or not ? If not supported then validate it on server. What do you say ? Please make me clear


      Sincerly Navaneeth My Website

      B R 2 Replies Last reply
      0
      • N N a v a n e e t h

        Christian Graus wrote:

        You CANNOT disable it. Anything that is selected via javascript, MUST be validated on the server side before performing any actions.

        Then what will be the use of javascript if we are rechecking everything in server before processing ? Or is it possible to identify javascript is supported by the browser or not ? If not supported then validate it on server. What do you say ? Please make me clear


        Sincerly Navaneeth My Website

        B Offline
        B Offline
        badgrs
        wrote on last edited by
        #4

        Navaneeth. wrote:

        Or is it possible to identify javascript is supported by the browser or not ? If not supported then validate it on server

        Thats not the point that was made. The point is that the client (and any javascript methods) cannot be trusted. As was the original question, a user with some javascript know-how can manipulate the form. The point of javascript is to make things easier for the user, like disabling the check boxes so its obvious they can't use them, rather than waiting for a postback only to be told they did something wrong. Javascript should be used to enhance the users experience of an site/application, but should never be relied upon for security.

        1 Reply Last reply
        0
        • N N a v a n e e t h

          Christian Graus wrote:

          You CANNOT disable it. Anything that is selected via javascript, MUST be validated on the server side before performing any actions.

          Then what will be the use of javascript if we are rechecking everything in server before processing ? Or is it possible to identify javascript is supported by the browser or not ? If not supported then validate it on server. What do you say ? Please make me clear


          Sincerly Navaneeth My Website

          R Offline
          R Offline
          Russell Jones
          wrote on last edited by
          #5

          I tend to check data at every boundary of the application. I check that what the user put into my page is good. I then check that what the page submitted to ASP.Net is good. my ASP code then uses my Business Logic Layer which checks that the data it receives is good. I don't specifically check that the data entering the database is good but i do have rigorous constraints set up on all databases and I make sure that only objects written by my team have direct writeable access to the DB. I also know that those objects have been repeatedly unit tested before they are released. You can never check data enough in my opinion especially if those data may have been submitted by an external actor beyond your control. eg web user, public webservice, contract developer. This approach may be bordering on the paranoid but it makes applications far more stable especially as the type of checking that occurs at each level is likely to be different and therefore catches a different set of errors that may occur. Russ

          1 Reply Last reply
          0
          • A Ahmad Safwat

            Hi guys, I need a help please In my asp.net 2 pages, when I disable some controls on page, user can run some javascript code in address bar that enables my disabled controls, that will cause un-needed results for example A gridview that lists exams with a checkbox for each exam, when at least one student has launched an exam, I disable its checkbox so that instructor cannot delete it Now how can I prevent user from running javascript code from address bar to enable that checkbox, then delete exam

            A Offline
            A Offline
            Ahmad Safwat
            wrote on last edited by
            #6

            Hey people, I think you didn't understand me I have a button - for example - on my web form In some cases I disable this button by server side code, no problem Now my question is: Can any user openning this page execute javascript code from browser's address bar to enable that button?? And if yes, how can I prevent user from doing that??

            B 1 Reply Last reply
            0
            • A Ahmad Safwat

              Hey people, I think you didn't understand me I have a button - for example - on my web form In some cases I disable this button by server side code, no problem Now my question is: Can any user openning this page execute javascript code from browser's address bar to enable that button?? And if yes, how can I prevent user from doing that??

              B Offline
              B Offline
              badgrs
              wrote on last edited by
              #7

              We understood you perfectly.

              Ahmad Safwat wrote:

              Can any user openning this page execute javascript code from browser's address bar to enable that button??

              Yes.

              Ahmad Safwat wrote:

              And if yes, how can I prevent user from doing that??

              You can't, which is the point we were trying to make. Go ahead and disable the button, but don't make that the only means to stop users doing whatever function is attached to it in the code-behind. You could always set its Visible property instead so it won't even be rendered to the client.

              A 1 Reply Last reply
              0
              • B badgrs

                We understood you perfectly.

                Ahmad Safwat wrote:

                Can any user openning this page execute javascript code from browser's address bar to enable that button??

                Yes.

                Ahmad Safwat wrote:

                And if yes, how can I prevent user from doing that??

                You can't, which is the point we were trying to make. Go ahead and disable the button, but don't make that the only means to stop users doing whatever function is attached to it in the code-behind. You could always set its Visible property instead so it won't even be rendered to the client.

                A Offline
                A Offline
                Ahmad Safwat
                wrote on last edited by
                #8

                hi badgrs, thanx my dear, I already hide controls instead of disabling them, but I thought there may be a better solution that I don't know I don't want to check user's javascript code, I need to block scripting I need to prevent users from run any javascript code on my page Is this possible because hiding controls sometimes make the page looks bad :( thanx again

                B 1 Reply Last reply
                0
                • A Ahmad Safwat

                  hi badgrs, thanx my dear, I already hide controls instead of disabling them, but I thought there may be a better solution that I don't know I don't want to check user's javascript code, I need to block scripting I need to prevent users from run any javascript code on my page Is this possible because hiding controls sometimes make the page looks bad :( thanx again

                  B Offline
                  B Offline
                  badgrs
                  wrote on last edited by
                  #9

                  Ahmad Safwat wrote:

                  I need to prevent users from run any javascript code on my page Is this possible

                  No.

                  A 1 Reply Last reply
                  0
                  • B badgrs

                    Ahmad Safwat wrote:

                    I need to prevent users from run any javascript code on my page Is this possible

                    No.

                    A Offline
                    A Offline
                    Ahmad Safwat
                    wrote on last edited by
                    #10

                    :((:((:((:(( thanx my dear :)

                    B 1 Reply Last reply
                    0
                    • A Ahmad Safwat

                      :((:((:((:(( thanx my dear :)

                      B Offline
                      B Offline
                      badgrs
                      wrote on last edited by
                      #11

                      Ahmad Safwat wrote:

                      thanx my dear

                      Hmm, thats usually a phrase my ganny says to me... Let me elaborate a bit, no isn't a very explanatory answer: Ultimately you have no control what-so-ever over the browser. You can (and should) do everything possible to make things easier for the user, but you should never try to stop them doing anything. If they want to screw things up thats their problem, let them do it, just make sure you have sufficient validation in place server-side.

                      A 1 Reply Last reply
                      0
                      • B badgrs

                        Ahmad Safwat wrote:

                        thanx my dear

                        Hmm, thats usually a phrase my ganny says to me... Let me elaborate a bit, no isn't a very explanatory answer: Ultimately you have no control what-so-ever over the browser. You can (and should) do everything possible to make things easier for the user, but you should never try to stop them doing anything. If they want to screw things up thats their problem, let them do it, just make sure you have sufficient validation in place server-side.

                        A Offline
                        A Offline
                        Ahmad Safwat
                        wrote on last edited by
                        #12

                        Hmmmm, thanx my dear ;P This is really a good advice thank u

                        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