Plugin Directory

Changeset 3763334


Ignore:
Timestamp:
10/24/2026 01:47:30 PM (17 hours ago)
Author:
vrcs66
Message:

Version 2.3 security patch

Location:
chat-ai-with-dispatcher/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • chat-ai-with-dispatcher/trunk/chat-ai-with-dispatcher.php

    r3451405 r3763334  
    1616 * Plugin Name: Chat AI with Dispatcher
    1717 * Description: A free live chat solution with AI and human supervision.
    18  * Version: 2.2
     18 * Version: 2.3
    1919 * Author: Csaba Váradi
    2020 * Author URI: https://www.vrcs.hu/
  • chat-ai-with-dispatcher/trunk/includes/frontend/frontend-chataiwd-module.php

    r3451405 r3763334  
    737737        'name'     => isset( $_FILES['attachment']['name'] ) ? sanitize_file_name( wp_unslash( $_FILES['attachment']['name'] ) ) : '',
    738738        'type'     => isset( $_FILES['attachment']['type'] ) ? sanitize_mime_type( wp_unslash( $_FILES['attachment']['type'] ) ) : '',
    739         'tmp_name' => $tmp_name, // Itt az eredeti C:/wamp64/... útvonal marad meg
     739        'tmp_name' => $tmp_name,
    740740        'size'     => isset( $_FILES['attachment']['size'] ) ? (int) $_FILES['attachment']['size'] : 0,
    741741    );
    742742
    743 
    744 
    745 
    746     // PDF gyors kezelése
     743    // PDF gyors kezelése (változatlanul hagyva)
    747744    if ($file['type'] === 'application/pdf') {
    748         $pdf_icon = plugins_url('assets/images/pdf_icon.png', dirname(__FILE__)); // Ellenőrizd az útvonalat!
     745        $pdf_icon = plugins_url('assets/images/pdf_icon.png', dirname(__FILE__));
    749746        $json['success']          = true;
    750747        $json['thumbnail_url']    = $pdf_icon;
    … …  
    757754    $base_dir   = $upload_dir['basedir'];
    758755
    759     // Mappa kezelése - JAVÍTVA
    760756    $temp_sub_dir = 'chataiwd_temp/';
    761757    $temp_dir     = trailingslashit($base_dir) . $temp_sub_dir;
    … …  
    765761    }
    766762
    767     // Fájlnév generálása (érdemes egy egyedi ID-t elé tenni, mint OC-ben, hogy ne írják felül egymást)
    768     $filename = time() . '-' . $file['name'];
     763    // 1. JAVÍTÁS (AUTOMATTIC KÉRÉSE): A basename() hozzáadása a fájlnévhez, hogy ne lehessen ../ trükk:
     764    $filename = time() . '-' . basename( $file['name'] );
    769765    $copied_file_path = $temp_dir . $filename;
    770766
    … …  
    774770    }
    775771
    776     // MIME ellenőrzés finfo-val
     772    // MIME ellenőrzés finfo-val (változatlanul)
    777773    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    778774    $mime_type = finfo_file($finfo, $copied_file_path);
    … …  
    782778
    783779    if ( $is_image ) {
    784         // Itt hívod meg a resizing funkciót
    785780        $thumbnail_url = chataiwd_generate_resized_image( $copied_file_path, 160 );
    786781        $preview_url   = chataiwd_generate_resized_image( $copied_file_path, 500 );
    … …  
    791786        }
    792787
    793         $json['success']          = true;
    794         /*$json['thumbnail_url']    = $thumbnail_url;
    795         $json['preview_url']      = $preview_url;
    796         $json['copied_file_path'] = $temp_sub_dir . $filename; // Relatív útvonal
    797         */
    798 
    799         $json['thumbnail'] = $thumbnail_url;
     788        $json['success']        = true;
     789        $json['thumbnail']      = $thumbnail_url;
    800790        $json['temp_file_path'] = $preview_url;
    801791
    … …  
    803793
    804794    } else {
     795        // 2. JAVÍTÁS: Ha kiderül, hogy nem kép volt, azonnal letöröljük a másolatot a szerverről!
     796        if ( file_exists( $copied_file_path ) ) {
     797            wp_delete_file( $copied_file_path );
     798        }
     799
    805800        $json['error'] = 'Invalid image format.';
    806801        wp_send_json( $json );
    … …  
    816811
    817812    $json = array( 'success' => false );
    818     // FRISSÍTVE: A JS-ből 'copied_file_path'-ként kell érkeznie
    819     $copied_file_path = isset( $_POST['copied_file_path'] ) ? sanitize_text_field( wp_unslash( $_POST['copied_file_path'] ) ) : '';
    820 
    821     if ( empty( $copied_file_path ) ) {
    822         // ...
     813
     814    $raw_path = isset( $_POST['temp_file_path'] ) ? $_POST['temp_file_path'] : ( $_POST['copied_file_path'] ?? '' );
     815    $raw_path = sanitize_text_field( wp_unslash( $raw_path ) );
     816
     817    if ( empty( $raw_path ) ) {
     818        $json['error'] = 'Missing file path.';
     819        wp_send_json( $json );
     820        return;
    823821    }
    824822
    825823    $upload_dir = wp_upload_dir();
    826     // FRISSÍTVE: 'copied_file_path' használata
    827     $file_to_delete = trailingslashit( $upload_dir['basedir'] ) . $copied_file_path;
    828     $filename = basename( $file_to_delete );
    829 
    830     // Töröljük az eredeti másolatot
    831     if ( file_exists( $file_to_delete ) ) {
    832         wp_delete_file( $file_to_delete );
    833 
    834         // Próbáljuk törölni a hozzá tartozó ikont is
    835         $resized_dir = dirname( $file_to_delete ) . '/resized/';
    836 
    837         $icon_file_name = pathinfo($filename,PATHINFO_FILENAME) . '_160.' . pathinfo($filename,PATHINFO_EXTENSION);
    838         $resized_icon_path = $resized_dir . $icon_file_name;
    839 
    840         if ( file_exists( $resized_icon_path ) ) {
    841             wp_delete_file( $resized_icon_path ); // @ - hiba elnyomása, ha valamiért nem törölhető
    842         }
    843 
    844         // Törölhetjük a preview_500-at is, ha létezik (bár a JS hívás után ez elvileg a sendMessage-ben történik)
    845         $preview_file_name = pathinfo($filename,PATHINFO_FILENAME) . '500.' . pathinfo($filename,PATHINFO_EXTENSION);
    846         wp_delete_file( $resized_dir . $preview_file_name );
     824    $temp_dir   = trailingslashit( $upload_dir['basedir'] ) . 'chataiwd_temp';
     825    $real_temp_dir = realpath( $temp_dir );
     826
     827    $filename = basename( sanitize_file_name( $raw_path ) );
     828    $file_to_delete = trailingslashit( $temp_dir ) . $filename;
     829    $real_file_path = realpath( $file_to_delete );
     830
     831    if ( $real_temp_dir && $real_file_path && 0 === strpos( $real_file_path, $real_temp_dir ) && file_exists( $real_file_path ) ) {
     832
     833        wp_delete_file( $real_file_path );
     834
     835        $resized_dir = trailingslashit( $temp_dir ) . 'resized/';
     836        $real_resized_dir = realpath( $resized_dir );
     837
     838        if ( $real_resized_dir && is_dir( $real_resized_dir ) ) {
     839            $ext  = pathinfo( $filename, PATHINFO_EXTENSION );
     840            $name = pathinfo( $filename, PATHINFO_FILENAME );
     841
     842            $icon_file_name    = $name . '_160.' . $ext;
     843            $resized_icon_path = trailingslashit( $real_resized_dir ) . $icon_file_name;
     844            if ( file_exists( $resized_icon_path ) ) {
     845                wp_delete_file( $resized_icon_path );
     846            }
     847
     848            $preview_file_name = $name . '500.' . $ext;
     849            $preview_path      = trailingslashit( $real_resized_dir ) . $preview_file_name;
     850            if ( file_exists( $preview_path ) ) {
     851                wp_delete_file( $preview_path );
     852            }
     853        }
    847854
    848855        $json['success'] = true;
    849         _wp_send_json( $json );
    850     } else {
    851         $json['error'] = 'File not found.';
    852         wp_send_json( $json );
    853     }
     856        wp_send_json( $json );
     857        return;
     858    }
     859
     860    $json['error'] = 'File not found or access denied.';
     861    wp_send_json( $json );
    854862}
    855863
  • chat-ai-with-dispatcher/trunk/readme.txt

    r3451708 r3763334  
    55**Tested up to:** 6.9
    66**Requires PHP:** 7.4
    7 **Stable tag:** 2.2
     7**Stable tag:** 2.3
    88**License:** GPLv2 or later
    99**License URI:** https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    2323- Mobile-friendly and easy to install.
    2424
    25 [youtube https://youtu.be/i5akM_zmMOE]
     25[youtube https://youtu.be/3zQa2NOSucs]
    2626
    2727---
    … …  
    9898
    9999## Changelog
     100### 2.3.0
     101* Security fix: Path traversal prevention and directory containment check in temporary file handlers. (Credit: Muni Nitish Kumar Yaddala)
     102
    100103### 2.2.0
    101104* WhatsApp Integration: Direct WhatsApp contact button added to the chat interface with admin-configurable phone numbers.
Note: See TracChangeset for help on using the changeset viewer.