Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.08.07 22:24 
Beim Eintragen von Daten in die DB werden sie durch mysql_real_escape_string escaped. Wenn dort nun ein " vorkommt, wird daraus \". Okay, aber: Beim Anzeigen der Daten aus der DB stört dieses \. Wie kriegt man es weg? Ich möchte gerne das Gegenteil von mysql_real_escape_string erreichen.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Fr 24.08.07 22:27 
Beim auslesen aus der Datenbank sollten die Symbole nicht "escaped" sein!
Man muss also nichts zurückescapen.
Schau mal wie sie in der Datenbank drinstehen.

btw. Kennt jemand ein gutes deutsches Wort für "escape"?
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.08.07 22:30 
user profile iconarj hat folgendes geschrieben:
Beim auslesen aus der Datenbank sollten die Symbole nicht "escaped" sein!

Sind sie aber. Warum nicht? Ich bin der Meinung, dass gehört sich so, zum Schutz vor XSS und SQL-Injections (BenBE hat mir mal davon erzählt).
user profile iconarj hat folgendes geschrieben:
Man muss also nichts zurückescapen.

Doch. ;)
user profile iconarj hat folgendes geschrieben:
Schau mal wie sie in der Datenbank drinstehen.

Sie sind escaped.
user profile iconarj hat folgendes geschrieben:
btw. Kennt jemand ein gutes deutsches Wort für "escape"?

Ich würde in diesem Kontext von "entschärft" reden.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Fr 24.08.07 22:44 
Wenn das so ist, versuch mal stripslashes vielleicht reicht das schon.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.08.07 22:56 

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.08.07 23:06 
Hey super das funktioniert einwandfrei. :zustimm:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Fr 24.08.07 23:10 
user profile iconMarco D. hat folgendes geschrieben:
user profile iconarj hat folgendes geschrieben:
Beim auslesen aus der Datenbank sollten die Symbole nicht "escaped" sein!

Sind sie aber. Warum nicht? Ich bin der Meinung, dass gehört sich so, zum Schutz vor XSS und SQL-Injections (BenBE hat mir mal davon erzählt)


Mein Test hat mich gerade nicht davon überzeugt dass die Daten escaped dann in der Datenbank stehen.
Das würde mich auch sehr stark wundern.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.08.07 23:14 
Wo hast du getestet? Meinst du irgendetwas bestimmtes? :gruebel:
Wie soll das denn sonst gehen? Ich muss im Query alle Eingaben von außen escapen. Dann folgt doch daraus, dass diese auch so in der DB stehen.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 24.08.07 23:55 
Wenn die Daten escaped in der Datenbank stehen, hast Du einmal zuviel escaped.

Wenn Du diesen SQl-String hast:
ausblenden SQL-Anweisung
1:
INSERT INTO myTable VALUES ("blah \" blubb")					

steht in der Datenbank hinterher:
ausblenden Quelltext
1:
blah " blubb					


So steht auch Dein erstes Posting so in der DB, wie Du es oben siehst.

//edit: Ups, Notiz an mich, da ist ein Bug im SQL-Highlighter ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Sa 25.08.07 10:11 
Zitat:
Wenn die Daten escaped in der Datenbank stehen, hast Du einmal zuviel escaped.


Der Meinung bin ich allerdings auch ;)

Ich hab in etwa das getestet was Christian auch gemacht hat.

OT: Witzigerweise in eine Tabelle namens Blub *g*
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: So 26.08.07 21:00 
Ich bin gerade zufälligerweise auf dasselbe Problem gestoßen:

Bei mir war das Problem, dass ich folgendes gemacht hab:
ausblenden SQL-Anweisung
1:
2:
3:
$titel = mysql_real_escape_string($_POST["titel"]);
$sql = "INSERT INTO `table` (title) VALUES ('".$title."')";
echo $sql;


Wenn ich also in der Form
Zitat:
foo's bar
eingebeben habe war das Ergebnis folgendes:
Zitat:
INSERT INTO `table` (title) VALUES ('foo\\\'s bar)


Irgendwo wurde von PHP automatisch nochmals escaped.
Das Problem bleibt bestehen, wenn man einfache Anführungszeichen nimmt.
Auch eine Lösung mit sprintf bringt nichts :-/

Nach etwas googeln bin ich dann schließlich auf die Lösung gestoßen:
Der Schalter magic_quotes_gpc war aktiviert. Dadurch werden die Strings, die über GET, POST oder Cookies kommen automatisch
escaped. (vgl. magic_quotes_runtime)

Ich muss also den Titel selbst nicht mehr escapen:
ausblenden SQL-Anweisung
1:
2:
$titel = $_POST["titel"];
$sql = "INSERT INTO `table` (title) VALUES ('".$title."')";
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 26.08.07 23:16 
Diese automatische "Escape-Funktion" von PHP nennt sich "Magic Quotes Runtime" und ist Sicherheits-Technisch der letzte Dreck (geben selbst die von PHP zu) ... Wenn Du also kannst: Jegliche Magic Quotes-Settings abschalten ODER\UND ggf. Rückgängig machen UND (in beiden Fällen) SELBSTSTÄNDIG erneut mit mysql_real_escape_string entschärfen.

In jedem Fall sollte dein Script aber MIT BEIDEN Einstellungen für Runtime Magic Quotes zurechtkommen UND den sicheren Weg gehen. Ferner solltest Du auch die Einstellungen zu Magic Quotes GPC

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Arne K.
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
EE-Autor
Beiträge: 112


C# (VS 2008 Professional)
BeitragVerfasst: Mo 27.08.07 15:58 
In der Praxis prüft man meist zunächst, ob PHP < 6 installiert ist.
Wenn ja, prüft man, ob magic_quotes_gpc() aktiv ist.
Wenn ja, macht man ein array_map() mit einem stripslashes() auf alle superglobalen Input-Arrays.

Problem gelöst ;)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 27.08.07 18:10 
Mit Magic Quotes löst man halt die Probleme, die man ohne sie nicht hätte ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 27.08.07 22:11 
Ich kenne Delphi4PHP nicht, aber man sollte es vermeiden, Parameter direkt in die Query zu schreiben. Die Konversion zu String der Query und zurück zum gewünschten Datentyp ist unnötiger Overhead.

Bei indirekter Parameterübergabe ist der Daten-Typ bekannt, eine Konversion zu/von String entfällt, es ist kein Escapen/Unescapen nötig, die ganze Sache ist sicherer und der Code ist insgesamt übersichtlicher (da Daten vom Code getrennt sind).

Bsp:
SELECT * FROM TABLE WHERE ID = :MYID
Danach Parameter MYID übergeben (dürfte ähnlich aussehen wie Query.Params.ParamByName('MYID').AsInteger := 1).

Last but not least: Vom direkt reinkompilierten Queries in der Exe würd ich auch abraten (ab einer gewissen Grösse des Projektes auf jeden Fall). Stored procedures schreiben, falls die unterstützt werden.