Results 1 to 4 of 4

Thread: Validating malicious javascript

  1. #1
    Join Date
    Nov 2006

    Red face Validating malicious javascript

    Hi All,

    I have a need to create a web application which allows the user to design a web page using a web based wysiwyg editor. I also need to allow the user as much freedom as possible to design just what they require. The nearest example of this are the 'Sell' pages on EBay where you can enter a description of your item along with javascript, applets and of course HTML.

    If you type <script...>alert("Hello")</script> tag in the EBay description and click the "Save and Continue" button, your html will be rendered and displayed, and the "Hello" alert will appear. If you type location.href=("<url>"), it will attempt to go to that page, but EBay will somehow block the request after a few clicking sounds.

    My plan is to allow the user to enter anything they want, but on submission of the page I want to search for any potentially malicious Javascript commands and if they are found, then I will not allow the HTML to be saved. Javascript isn't my area of expertize (I am a DBA really), so I need to know what javascript keywords I should look for (location.href and alert are two I know of) to mitigate against the possibility of being hacked (cross-site scripting, for example) or the page misused.

    In addition to the keywords I require, any other comments \ opinions would be very welcome.

    Kind regards,


  2. #2
    Join Date
    Jun 2003

    I would advise against trying to write such a thing, as of course the main problems being either infinite loops(while(true){alert("ha-ha, you can't escape me");};) or such(things that are actually hard to pick up on).

    and to add insult to injury even if you wrote such a script to pick up on it I could simply encrypt it and decrypt it at a time of my choice.

    it might be better if you made a list of things you want the user to be able to do and you restrict the javascript to that and that alone.
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  3. #3
    Join Date
    May 2003
    Between Baltimore and DC
    All of the checking should be done on the server. I do not have to use your form to submit it to the server.

    Look at my talk here (it is a zip): http://www.pascarello.com/presentation/owasp/

    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  4. #4
    Join Date
    Nov 2006
    Thank you both for your comments.

    Alien, the checking will indeed be done on the server.

    I understand that it is inadvisable to put a system like this into production; I also would recommend against it under most circumstances. However, this interface is central to the application, and I can't let the possibility of users hacking \ misusing the page stop the project - I just have to take every possible step to reduce the chances of it happening. The user would have had to provide a valid email address, and part with some money in order to get to this page, so the chances of them misusing the page are already reduced.

    If I have to check each and every submission that contains a <script> tag after it has been submitted, then that's what I will do. However, the fact remains that I would like to trap the most common potentially malicious keywords and prevent submission if the html contains them (or email me to prompt me to check the submission).

    the 'while' keyword is a useful one for the list, Scragar, and I would be grateful for any others you can come up with.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09783 seconds
  • Memory Usage 2,859KB
  • Queries Executed 13 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates