tami: PHP json_encode - kontextspezifisches Escaping

Beitrag lesen

hi tami,

hi Sven,

Moin!

<?php ### buecher.js.php ###
    header('Content-Type: Text/Javascript; Charset=utf-8');
    session_start();
    echo 'var buecher = new Array("' . implode('","', $_SESSION['buecher']) .'");' . PHP_EOL;
?>

In dem Code ist keinerlei kontextgerechtes Escaping drin! Er ist gefährlich! Bitte nicht benutzen!

Wäre denn json_encode ausreichend?

"

<?php

$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

echo json_encode($arr);
?>


>   
> The above example will output:  
>   
> {"a":1,"b":2,"c":3,"d":4,"e":5}  
>   
> [http://php.net/manual/en/function.json-encode.php](http://php.net/manual/en/function.json-encode.php).  
>   
> Ggfs. auch: [http://stackoverflow.com/questions/12062146/is-json-encode-sufficient-xss-protection](http://stackoverflow.com/questions/12062146/is-json-encode-sufficient-xss-protection).  
  
Und <http://framework.zend.com/manual/2.1/en/modules/zend.escaper.escaping-javascript.html>  
  
mfg  
  
tami
0 48

PHP array an javascript function übergeben

javascriptnewbie
  • javascript
  1. 0
    dedlfix
  2. 0
    Der Martin
    1. 0
      molily
    2. 0
      javascriptnewbie
      1. 0
        M.
        1. 0

          Gute Idee

          Tom
          • menschelei
      2. 1
        ChrisB
        1. 0
          javascriptnewbie
          1. 0
            molily
            1. 0
              javascriptnewbie
              1. 0
                M.
              2. 6
                molily
      3. 0
        Tom
        1. 0
          javascriptnewbie
          1. 0
            Tom
            1. 0
              Sven Rautenberg
              1. 0

                Nicht nur meckern, zeigen! Escaping für JavaScript-Variablen

                Tom
                1. 0
                  molily
                  1. 0
                    tami
                    1. 0
                      molily
                      1. 0
                        tami
                  2. 0
                    Tom
                    1. 0
                      molily
              2. 0

                PHP json_encode - kontextspezifisches Escaping

                tami
                1. 0
                  tami
                  1. 0
                    molily
                    1. 0
                      Sven Rautenberg
                      1. 0
                        molily
                        1. 0
                          molily
                        2. 0

                          JSON in HTML einbetten

                          molily
                          1. 1

                            JSON in HTML einbetten - RoR "vs" ZF

                            tami
                            1. 0
                              tami
                              1. 0
                                Tom
                                1. 0
                                  molily
                            2. 0
                              molily
                              1. 0
                                tami
                                1. 0
                                  tami
                              2. 0

                                JSON-Paket mit composer vom Zend Framework holen

                                tami
                              3. 2

                                JSON in HTML einbetten

                                molily
                                • php
                          2. 0

                            Reihenfolge der Auswertung?

                            Tom
                            1. 0
                              tami
                            2. 0
                              tami
                            3. 0

                              Reihenfolge der Auswertung? Codierung, kleine Korrektur

                              Tom
                            4. 0
                              molily
                              1. 0
                                Tom
                                1. 0
                                  molily
                  2. 0
                    Tom