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

Beitrag lesen

hi molily,

Hallo,

echo 'var buecher = new Array("' . implode('","', $_SESSION['buecher']) .'");' . PHP_EOL;

Bitte nicht nur meckern, sondern zeigen, wie es geht!

Die saubere Lösung hatte ChrisB schon aufgezeigt, sie lautet JSON.

Was müssen wir also escapen? Das zu diskutieren, wäre doch wünschenswert!

Das kommt auf den Kontext an. Hier ist der Kontext ein JavaScript-String.

Was ist mit: "Escaping Javascript

Javascript string literals in HTML are subject to significant restrictions particularly due to the potential for unquoted attributes and any uncertainty as to whether Javascript will be viewed as being CDATA or PCDATA by the browser. To eliminate any possible XSS vulnerabilities, Javascript escaping for HTML extends the escaping rules of both ECMAScript and JSON to include any potentially dangerous character. Very similar to HTML attribute value escaping, this means escaping everything except basic alphanumeric characters and the comma, period and underscore characters as hexadecimal or unicode escapes.

Javascript escaping applies to all literal strings and digits. It is not possible to safely escape other Javascript markup.

To escape data in the Javascript context, use Zend\Escaper\Escaper‘s escapeJs method. An extended set of characters are escaped beyond ECMAScript’s rules for Javascript literal string escaping in order to prevent misinterpretation of Javascript as HTML leading to the injection of special characters and entities."?

http://framework.zend.com/manual/2.1/en/modules/zend.escaper.escaping-javascript.html bzw. https://forum.selfhtml.org/?t=217757&m=1496870

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