Autor Beitrag
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 31.05.08 17:06 
Hallo,

ich bastle momentan mal wieder an einem eigenem Templatesystem. Dabei stehe ich vor dem problem, dass ich Dateien per include einbinde um Code ausführen zu können. Um aber eine dadurch gegebene Sicherheitslücke zu schließen, muss ich folgendes verhindern:

ausblenden Quelltext
1:
Ich soll <?php nicht?><? geparste ?>werden, aber diese Variable schon: {blubb}					

Überstzt von meinem Code würde das dann so hier sein:

ausblenden Quelltext
1:
Ich soll <?php nicht?><? geparste ?>werden, aber diese Variable schon: <?php echo $var["blubb"] ?>					


Wie man erkennt, werde die <?php etc. nicht ersetzt. Besteht da eine möglichkeit diesen Fehler zu unterbinden - ohne aus <?
das hier zu machen?
ausblenden Quelltext
1:
<?php echo "<?"; ?>					


Grüße
Heiko
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 31.05.08 17:13 
Eigentlich doch nur < und > vorher maskieren als &lt; und &gt; oder?

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Heiko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 31.05.08 17:16 
Den Code wollte ich eigentlich nicht verändern, denn bei XML dürfte es ja bei deinem Probleme geben...
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 31.05.08 17:27 
Dann matche auf '<\?php(.?)\?>' und replace das mit '&lt;?php$1?&gt;'. Dürfte doch dann eigentlich keine Probleme geben?

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Heiko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 31.05.08 20:01 
Sagen wir es so: es ist wohl die einzige php-lose Variante - auch wenn es nicht im Sinne eines Templatesystems ist. Vermutlich ist meine Variante die einzige, die funzt...

PS: Den ?>-Tag muss man nicht beachten. Nur die Kombination <?
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 01.06.08 12:33 
Schon, aber > ist trotzdem kein Valid Char. Auch wenns funktioniert ;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Heiko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 01.06.08 12:43 
Nur mal zur Verdeutlichung des Problems:

Wenn nen template so aussähe:
ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
<html>
<head>
  <title>{MyTitle}</title>
</head>
<body>
<!-- ... -->
</body>
</html>


Das würde bei der Ersetzung dann nimmer gehen ;)
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 02.06.08 01:09 
Deswegen auch beides Matchen... Aber so in der Form wirst du eh immer invaliden Code erzeugen. Dann stört das eine Zeichen mehr oder weniger natürlich nicht ;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Mo 02.06.08 14:22 
Ich würde einfach mit str_replace() (kein preg_replace) <? durch &lt;? und ?> durch ?&gt; ersetzen.
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Fr 06.06.08 18:21 
Bei meinem Template System parse ich das File sozusagen vor. Dann entferne ich alles, was ich nicht drin haben will, und meine eigenen "tags" werden direkt in php code umgewandelt, so dass ich dann beim Include nix mehr machen muss. z.B. aus {V_IRGEND_EINE_VARIABLE( wird be mir dann: <?php echo $this->theme->getVar('IRGEND_EINE_VARIABLE'); ?>

schlussendlich habe ich dann 2 files, einmal vorgeparst und einmal normal, um es bearbeiten zu können.

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
Heiko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Fr 06.06.08 18:56 
Japp, das ist auch mein Ziel (Smarty etc. macht es ja auch so). Im Prinzip ist das TPL-System nur dazu da, um den Code überschaubarer zu machen - und bissl wegen Sicherheit.
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Sa 07.06.08 14:10 
Du kannst ja nach <?php suchen, und das im vorgeparsten Template als <?php echo '<?php'; ?> schreiben.
Ich hab shcon gesehen, dass du das nicht willst, aber ich denke nicht dass es einen besseren weg gibt.

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
Sirke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 208
Erhaltene Danke: 2



BeitragVerfasst: Mo 09.06.08 23:30 
Ich verstehe das Problem ehrlich gesagt nicht! Ein Template wird vom Administrator verarbeitet und dieser sollte Ahnung von der Verwendung des Templates haben, sodass keine PHP-Tags in dem Quelltext auftauchen sollten!

Ich verwende eval() zum Parsen meines Templates. Ein Zeile <b>{var}</b> würde dann eval("echo '<b>$var</b>\n';"); lauten und ausgeführt werden! Da nur Personen die das Template kennen dieses verwenden, sollte es nicht zu Fehlern kommen!!