Así que estoy en camino de lanzar un buen complemento, pero hay un problema, que en realidad no es un problema debido a cómo se administran los nombres de archivos en el lado del servidor. De todos modos, ¿conoce otra forma de solucionar este problema?
NO hay forma de pasar el contenido correcto si se pasa utilizando las formas comunes de WP.
Instalé el complemento de validación para verificar, pero en realidad esto no se puede resolver de otra manera y, como dije, de todos modos es absolutamente seguro, entonces, ¿te irá bien?
PD: de todos modos, está bien también porque todos los procesos de cifrado y descifrado se realizan en el navegador.
El servidor nunca ve datos reales y cualquiera que pueda descargar el archivo no hará demasiado sin poseer la clave privada ML-KEM 1024.
public function get_encrypted_content( $request ) {
$filename = sanitize_file_name($request->get_param('file'));
$token = sanitize_text_field($request->get_param('key'));
$saved_token = get_option( 'w3token_' . $filename );if ( $saved_token && $saved_token === $token ) {
$upload_dir = wp_upload_dir();
$file_path = $upload_dir['basedir'] . '/w3mypgp_vault/' . $filename;
// Could be used js fetch on frontend but why? It is not reliable
// return new WP_REST_Response( array( 'success' => true, 'message' => $filename ), 200 );
if ( file_exists($file_path) ) {
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($file_path));
if (ob_get_level()) ob_end_clean();
/* // THIS DO NOT WILL WORK
require_once ABSPATH . 'wp-admin/includes/file.php';
if ( WP_Filesystem() && file_exists($file_path) ) {
global $wp_filesystem;
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($file_path));
if (ob_get_level()) ob_end_clean();
// NOTE: wp_kses_post corrupt bits and make it fail the decryption
// wp_kses_post cannot be used
// $content = $wp_filesystem->get_contents( $file_path );
// echo wp_kses_post( $content ); # fail
// echo $content; # Ok. but maybe not safe
}*/
/* This way works and it's safe. The file path is the one stored and cannot be otherwise
Input Validation: Since we used sanitize_file_name, a hacker cannot request ../../wp-config.php. They can only request files inside our vault.
Token Check: the code already checks if the $token matches. Only someone with the correct link can trigger the stream.
Conclusion: Don't try to sanitize the binary bits. The output is a binary ciphertext for Post-Quantum decryption (ML-KEM); sanitizing the output would corrupt the cryptographic integrity.
*/
$fp = fopen($file_path, 'rb');
fpassthru($fp);
fclose($fp);
// readfile also works
// Dump the file bits to the network stream
// readfile($file_path);
// SELF-DESTRUCT
// unlink($file_path);
// delete_option('w3token_' . $filename);
// STOP HERE. Do not let WordPress send out any more data.
exit;
}
// Only if the file/token is wrong return a standard error
return new WP_Error('fail', 'Invalid link.', array('status' => 404));
}
}
Este tema fue modificado hace 16 horas y 53 minutos por .
Este tema fue modificado hace 16 horas y 51 minutos por .