Rich Text Editor & Safe HTML

Discussion in 'PHP' started by johnlaiz, Mar 28, 2006.

  1. #1
    i want to use rte for my blog script, let my user use / input html code.

    my question is ..

    how to make sure their input is safe?

    and what is unsafe html/code?

    thanks a lot!
     
    johnlaiz, Mar 28, 2006 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How would you be storying the data.

    You should NEVER store htm code into a MySQL db

    You could str_replacee ("<","[",$test)

    Then you can check the code yourself, make sure it is safe, (not calling any of your scripts ect);
     
    onlyican.com, Mar 28, 2006 IP
  3. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #3
    could you please explain the disadvantages of storing html data in databases?
     
    vishwaa, Mar 28, 2006 IP
  4. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It makes it more hackable, and more open to dangerous code
     
    onlyican.com, Mar 28, 2006 IP
  5. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #5
    im little bit confused... may be i am wrong!

    I normally use mysql_real_escape_string function to avoid such hacks in the mysql queries.

    What if im storing the html data in blob format and also use safe mysql queries?

    Is my database still vulnerable?
     
    vishwaa, Mar 28, 2006 IP
  6. johnlaiz

    johnlaiz Active Member

    Messages:
    387
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    58
    #6

    safe queries?
    i want to know besides "mysql_real_escape_string" ?
    how to make it more safe?

    ^^
     
    johnlaiz, Mar 28, 2006 IP
  7. johnlaiz

    johnlaiz Active Member

    Messages:
    387
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    58
    #7
    yes.. you are right, but how to store htm code into mysql db and safe?

    you mean use [] instead of <>?
     
    johnlaiz, Mar 28, 2006 IP
  8. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #8
    From http://in2.php.net/mysql_real_escape_string
    can anyone give me few examples of sql injection or any other attacks when storing html data in database?
     
    vishwaa, Mar 28, 2006 IP
  9. johnlaiz

    johnlaiz Active Member

    Messages:
    387
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    58
    #9
    the past few days ...
    i did search in google and read many web page about
    safe html , but still can't get any idea how to write my
    script to prevent unsafe html code.

    i just get some info like
    " Open comments or '<![CDATA[' are dangerous "


    now I want to know more any other code i need to convert it or replace...
     
    johnlaiz, Mar 28, 2006 IP
  10. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #10
    use strip_tags function to strip out unwanted html tags from user inputs.

    you might want to read full details here:http://in2.php.net/strip_tags
     
    vishwaa, Mar 28, 2006 IP
  11. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    onlyican.com, Mar 28, 2006 IP
  12. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Just for the record, you can store *anything*, apart from oreos & milk, in your mysql database as long as you pass it through the mysql_real_escape_string function first. Period. This means HTML, C++ code, an SQL query- anything. There will be no errors, risks or "unsafety". If you still don't like the idea of naked HTML sitting in your database, use base64_encode on it on the way in and base64_decode on the way out. The only side-effect will be a bloated table.
     
    exam, Mar 28, 2006 IP
  13. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #13
    You can use fck editor
     
    jitesh, Mar 28, 2006 IP
  14. johnlaiz

    johnlaiz Active Member

    Messages:
    387
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    58
    #14
    yes ... u r right

    because
    some of my script use
    base64_encode
    and
    base64_decode
    ...
     
    johnlaiz, Mar 29, 2006 IP
  15. johnlaiz

    johnlaiz Active Member

    Messages:
    387
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    58
    #15
    what is fck editor? fck stand for?


    thanks onlyican and vishwaa
    :)
     
    johnlaiz, Mar 29, 2006 IP
  16. wwm

    wwm Peon

    Messages:
    308
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #16
    there is no problems storing html in database as long as mysql_real_escape_string function is use


    now the problem is if one of your users attaches javascript along with html

    then your screwed, and its very very very hard to filter javascript out
     
    wwm, Mar 29, 2006 IP
  17. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #17
    The best way to get around this is to use fopen functions

    create a new file each time, and store the file name in the database.

    Then when you want to call the file, you use require.
     
    onlyican.com, Mar 29, 2006 IP
  18. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Why? Where is the problem?

    Um, not for me :)
     
    exam, Mar 29, 2006 IP
  19. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #19
    you can simply use the function preg_replace to filter out the javascript/style/class codes in your html.
     
    vishwaa, Mar 29, 2006 IP
  20. wwm

    wwm Peon

    Messages:
    308
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #20
    um i said hard not impossible ;)

    theres just so many ways javascript could be injected :(


    umh someone posting jscripts to redirect away from your site, set cookies etc.. search google, you dont want people posting javascript
     
    wwm, Mar 29, 2006 IP