You need to sign in to do that
Don't have an account?
Prevent XSS is Force.com Application
Greetings, I am working on the Prevent XSS in Force.Com Applications Trailhead, so far I've gotten most of the sections cleared. However, I seem to be stuck with this one. I've attempted many ways to assign JSENCODE, HTMLENCODE and JSINHTMLENCODE where needed but seem to stuck, are there any steps I should take here. My code's below. Hope it helps!
<apex:page controller="XSS_Mitigations_Challenge" sidebar="false" tabStyle="XSS_Mitigations_Challenge__tab"> <apex:sectionHeader title="XSS Mitigations Challenge" /> <apex:form > <apex:pageBlock > <apex:pageMessages /> <apex:pageBlockSection title="Demo" columns="1" id="tableBlock"> <c:codeLink type="Visualforce" namespace="" edit="true" name="XSS_Mitigations_Challenge" description="Edit this Visualforce page to perform the challenge."/> <apex:outputText value="{!JSENCODE(sampleMergeField1)}"/> <apex:outputText value="{!HTMLENCODE(sampleMergeField2)}" escape="false"/> <apex:outputText > {!sampleMergeField3} </apex:outputText> <script> document.write('{!JSENCODE(sampleMergeField4)}'); </script> {!sampleMergeField5} <script> var x = '{!JSENCODE(sampleMergeField6)}'; </script> <apex:outputLabel value="{!sampleMergeField7}" escape="false"/> </apex:pageBlockSection> <apex:pageBlockSection title="Code links" columns="1"> <apex:outputPanel > <ul> <li><c:codeLink type="Visualforce" namespace="" name="XSS_Mitigations_Challenge" description="Visualforce Page"/></li> <li><c:codeLink type="Apex" namespace="" name="XSS_Mitigations_Challenge" description="Apex Controller"/></li> </ul> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
As much as I'd like to give you an answer, it appears that I'm just as stuck as you are on this module. Here's my code if it'll help you or the solver of this problem:
My rationale behind what I've done:
- Does not appear to be susceptible to JavaScript attacks, and escape="true", so I left it alone.
- Again, it doesn not appear to be susceptible to JS, but escape="false", so I used HTMLENCODE().
- Not sure on this one, so I left it alone.
- It's inbetween script tags, so I used JSENCODE() to prevent JS attacks.
- I tried this both with and without HTMENCODE(). No luck. I'm not sure why it would need it though...
- Again, it's inbetween script tags, so I used JSENCODE().
- escape="false", so it needs HTMLENCODE()
There's my two cents, which, in this case, doesn't do me a whole lot of good.Best Regards,
Parker
All Answers
As much as I'd like to give you an answer, it appears that I'm just as stuck as you are on this module. Here's my code if it'll help you or the solver of this problem:
My rationale behind what I've done:
- Does not appear to be susceptible to JavaScript attacks, and escape="true", so I left it alone.
- Again, it doesn not appear to be susceptible to JS, but escape="false", so I used HTMLENCODE().
- Not sure on this one, so I left it alone.
- It's inbetween script tags, so I used JSENCODE() to prevent JS attacks.
- I tried this both with and without HTMENCODE(). No luck. I'm not sure why it would need it though...
- Again, it's inbetween script tags, so I used JSENCODE().
- escape="false", so it needs HTMLENCODE()
There's my two cents, which, in this case, doesn't do me a whole lot of good.Best Regards,
Parker
It works! Thank you for posting the correct code. I'm not a developer, so my only question is why does #4 need JSINHTMLENCODE() instead of just JSENCODE()? Is there something about "document.write()" that requires that?
Thanks again,
Parker
This worked for me, which is same as
@MedhanieHabte post.
Also when I was testing, I just logged out of the Developer org, and then asked trailhead to check the challenge.