encodeForHtml()
(nuovo in CF10) vs htmlEditFormat()
, in che modo sono diversi?encodeForHtml() vs htmlEditFormat()
risposta
Penso che sia lo stesso della funzione encodeForHTML in ESAPI OWASP di Java. Più sicuro per evitare l'attacco XSS per utilizzare il contenuto in HTML.
<cfsavecontent variable="htmlcontent">
<html>
<head>
<script>function hello() {alert('hello')}</script>
</head>
<body>
<a href="#bookmark">Book Mark & Anchor</a><br/>
<div class="xyz">Div contains & here.</div>
<IMG SRC=javascript:alert(&# x27XSS')>
<IMG SRC=javascript:alert('XSS')>
</body>
</html></cfsavecontent>
<cfoutput>#htmleditformat(htmlcontent)#</cfoutput>
<br />
<cfoutput>#encodeforhtml(htmlcontent)#</cfoutput>
Le funzioni di EncodeFor * sono basate sulle librerie ESAPI OWASP. La differenza principale è che HTMLEditFormat() sostituisce semplicemente "cattivi" stringhe, come &
, <
e >
con buone corde, come &
, <
e >
mentre EncodeForHTML() è più intelligente, con un vantaggio di essere essa in grado di riconoscere il contenuto che è già codificato e non la doppia codifica.
Ad esempio, se un utente ha presentato il seguente contenuto per il vostro sito:
<div>
Here is <i>test</i> html content includes<br/>
<script>alert('hello')</script>
Notice how & rendered with both functions.
</div>
Sia HTMLEditFormat() e EncodeForHTML() sarebbe correttamente sfuggire i personaggi '<' e '>'. Ma HTMLEditFormat() avrebbe codificare ciecamente la &
ancora una volta in modo tale che l'output assomiglia:
... how &amp; rendered ...
Dove sarebbe altrimenti simile con encodeForHTML():
... how & rendered ...
HTMLEditFormat() couldn Posso dire che la e commerciale era già codificata, quindi è stata ricodificata nuovamente. Questo è un esempio banale, ma dimostra come le librerie ESAPI siano più intelligenti e, quindi, più sicure.
In conclusione, non c'è motivo di utilizzare HTMLEditFormat() in CF10 +. Per la massima protezione, è necessario sostituire le funzioni di formattazione con le funzioni di codifica.
L'esempio completo sopra e più di fondo sono a isummation: http://www.isummation.com/blog/day-2-avoid-cross-site-scripting-xss-using-coldfusion-10-part-1/
- 1. è XmlFormat() sempre migliore di htmlEditFormat()?
- 2. ID vs UniqueID vs ClientID vs UniqueClientID vs StaticClientID?
- 3. VS 2008 vs VS 2008 Express
- 4. .NET vs ASP.NET vs CLR vs ASP
- 5. Atomikos vs JOTM vs Bitronix vs?
- 6. Accumulare vs piega vs ridurre vs comprimere
- 7. ACE vs Boost vs Poco vs wxWidgets
- 8. VS 2013 MSTest vs nUnit vs xUnit
- 9. control.BeginInvoke() Vs Dispatcher Vs SynchronizationContext Vs .. - AFFIDABILITÀ
- 10. Exec vs ExecWait vs ExecShell vs nsExec :: Exec vs nsExec :: ExecToLog vs nsExec :: ExecToStack vs ExecDos vs ExeCmd
- 11. bigtable vs cassandra vs simpledb vs dynamo vs couchdb vs hypertable vs riak vs hbase, cosa hanno in comune?
- 12. e vs * e | vs +
- 13. SpiderMonkey vs JavaScriptCore vs?
- 14. * vs ** vs *** in Proguard?
- 15. bundler vs RVM vs gemme vs RubyGems vs gemsets vs system ruby
- 16. Misurare il tempo in Linux - tempo vs orologio vs getrusage vs clock_gettime vs gettimeofday vs timespec_get?
- 17. innerText vs innerHtml vs label vs text vs textContent vs outerText
- 18. Mathematica: non valutata vs Defer vs attesa vs HoldForm vs HoldAllComplete vs etc etc
- 19. Iterator vs. Reference vs. pointer
- 20. Selenium vs. SimpleTest vs. WatiN
- 21. BasicHttpBinding vs WsHttpBinding vs webHttpBinding
- 22. Boo vs C# vs Python?
- 23. StringBuffer vs StringBuilder Vs StringTokenizer
- 24. JSF vs Facelets vs JSP
- 25. Qcodo vs. CakePHP vs. Zend
- 26. select vs poll vs epoll
- 27. RazorEngine vs RazorTemplates vs RazorMachine
- 28. cudaStreamSynchronize vs CudaDeviceSynchronize vs cudaThreadSynchronize
- 29. Bitmap vs ImageView vs Drawable
- 30. gruntjs vs yeoman vs guard
sembra strano che non avrebbero solo migliorare il tag pre-esistente tramite un altro attributo per renderlo più sicuro o semplicemente valorizzarlo fuori dalla scatola. – Snipe656
Bene, encodeForHtml() fa parte di un insieme: encodeForCss(), encodeForJavascript(), encodeForHtmlAttribute(), ecc. Dovrebbe anche scappare più del file originale htmlEditFormat(). – ale
Poiché utilizzano un output diverso, hanno aggiunto un nuovo tag come parte del set menzionato in precedenza anziché modificare il tag esistente. Ciò aiuta a mantenere la retrocompatibilità con il codice esistente. –