programing

WordPress의 기본 입력 검사를 방지합니다.

subpage 2023. 9. 26. 22:23
반응형

WordPress의 기본 입력 검사를 방지합니다.

A로부터 입력을 받을 때마다<textarea>혹은input파일, 워드프레스는 내 입력을 소독하고 모든 특수문자를 탈출합니다.이 기능을 비활성화하려면 어떻게 해야 합니까?예를 들어, 만약 내가 다음과 같은 C++ 코드를 받아들이는 html 코드를 가지고 있다면,cout<<"hello world";WordPress에서 다음으로 변환합니다.cout<<\"hello world\";.

<!--HTML code-->
<form action="/action.php" method="post">
  <input type="text" name="mycode" value="cout<<'hello world';">
  <input type="submit" value="Submit">
</form>

.

<?php
    //PHP code for action.php file
    echo $_POST['mycode'];//This output will have all the special characters escaped
    //I need this to give me the original text entered by the user without /s. 
?>

저는 워드프레스 버전 5.7.2를 사용하고 있습니다.특별한 캐릭터를 사용할 때마다 \, ', " 그들은 얻을 것입니다.\그들 앞에서저는 다른 워드프레스 테마를 사용해 보았는데 결과는 그대로입니다.사용하면stripcslashes($_POST['mycode'])이것들을 다 타라.\. 하지만 처음부터 워드프레스가 이런 짓을 하는 것을 막을 수 있는 방법이 없을까 생각하고 있었습니다.다음은 제가 얻은 입력과 출력의 이미지입니다.

enter image description here

stripslashes_deep($_POST['mycode'])효과가 있을 겁니다이 WordPress 기능은 배열이나 객체를 루프하는 동안 함수 스트립 슬래시에 내장된 PHP를 사용합니다.자세한 내용은 코드 참조.

WordPress는 마법 어록의 하위 호환성을 위해 이러한 슬래시를 추가하고 있습니다.버그 보고서를 통해 알 수 있듯이 지난 10년간 이에 대한 논의가 있었습니다.

여기 미친 듯이 간단한 해킹 아이디어가

맨 위에/index.php, WP가 수신 데이터에 욕심을 부리기 전에 다음 줄을 추가합니다.

$_SPOST = null;
if (isset($_SERVER['REQUEST_METHOD']) && strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
   $_SPOST = $_POST;
}

그런 다음 언제든지 코드 컨텐츠를 브라우저로 다시 전달할 수 있습니다.

<?php
    //PHP code for action.php file
    echo $_SPOST['mycode'];//This output will have all the special characters escaped
    //I need this to give me the original text entered by the user without /s. 
?>

하지만 잠깐만, 또..우리는 워드프레스 생태계 내에서 다시 연결하고 게시물을 조작하고 소독한 후에 우리의 게시물을 변형시킬 수 있습니다.

페이지에서는 현재 요청에 대한 모든 쿼리 변수가 구문 분석되면 실행되는 parse_request를 사용할 수 있는 아이디어를 제공했습니다.

function use_spost() {
  if (isset($_SPOST)) $_POST = $_SPOST;
}
add_action('parse_request', 'use_spost', 1);

필터를 사용할 수 있어야 합니다.

/*
* Filters the output from sanitize_text_field
* @param $filtered string - the sanitized string
* @param $original_string string - the original unsanitized string
*
* @return string - the unsanitized string
*/
add_filter( 'sanitize_text_field', static function( $filtered, $original_string ) { return $original_string; }, 10, 2 ); 

기본적으로, 필터링된 문자열을 비공개를 통해 반환하는 것보다_sanitize_text_field메서드는 입력에 전달된 원래 문자열을 반환합니다.

당신은 같은 일을 할 수 있습니다.textareas사용:sanitize_textarea_field

언급URL : https://stackoverflow.com/questions/68104290/prevent-wordpress-default-input-sanitization

반응형