내 URL의 해시를 가져 와서 정보를 사용하여 내 페이지의 다른 요소에 클래스를 설정할 수 있습니다. 이렇게하는 것은 간단하지만 XSS를 사용하여 취약해질 수 있으며 set 변수를 사용하기 전에 위생적으로 만들고 싶습니다. 문제는 그것이 작동하도록 할 수 없다는 것입니다.자바 스크립트에서 작동하도록 대체 할 수 없습니다.
예를 들어, url : www.my-domain.com/#gallery에서 "gallery"에 "hash"라는 변수를 설정하고 싶습니다.
하지만이 내용이 www.my-domain.com/#Hello<script>malicious payload</script>
과 같은지 확인하고 싶습니다. 3E
난 그냥 안녕하세요을받을 것으로 예상 안녕하세요 % 3Cscript % 3Enasty % 20payload % 3C/스크립트 %
문제는 콘솔이 다음과 같은보고 있다는 것입니다. 그래서, 분명히 나는 잘못된 것을하고 있습니다. 그러나 나는 그것을 알아 내지 못합니다. 나는이 같은 일을 시도
<script type="text/javascript">
jQuery(document).ready(function(){
var hash = document.URL.substr(document.URL.indexOf('#')+1);
hash = hash.replace(/<script[^>]*?>.*?<\/script>/gi, '').
replace(/<[\/\!]*?[^<>]*?>/gi, '').
replace(/<style[^>]*?>.*?<\/style>/gi, '').
replace(/<![\s\S]*?--[ \t\n\r]*>/gi, '');
console.log(hash); //Check the result in the console
if (hash === 'gallery' || hash === 'galleria' || hash === 'galleri') {
jQuery('#prod_description').removeClass('uk-active');
jQuery('#prod_gallery').addClass('uk-active');
} else
if (hash === 'relations') {
jQuery('#prod_description').removeClass('uk-active');
jQuery('#prod_relation').addClass('uk-active');
} else
if (hash === 'other') {
jQuery('#prod_description').removeClass('uk-active');
jQuery('#prod_other').addClass('uk-active');
} else
if (hash === 'promotion') {
jQuery('#prod_description').removeClass('uk-active');
jQuery('#prod_promotion').addClass('uk-active');
}
}
);
</script>
:
이
내 코드입니다 .replace ('L', '') 예상대로 즉, 첫 번째 인스턴스 작품 '해시의 난'이다 결과에서 제거되었습니다. 어느 날 내 정규 표현식이 잘못되었다고 생각하게 만들었으므로 다음과 같은 훨씬 간단한 접근법을 시도했습니다. .replace (/ [^ 0-9a-z]/gi, '')하지만 그 중 하나는 작동하지 않습니다.나는 무엇을하고 있는지에 대한 생각을 잘못하고 있습니까?
잘 dencode하지 않았다. – epascarello