Changeset 87095 in webkit


Ignore:
Timestamp:
May 23, 2011 1:47:06 PM (13 years ago)
Author:
adamk@chromium.org
Message:

2011-05-23 Adam Klein <adamk@chromium.org>

Reviewed by Jian Li.

[fileapi] Add a File::createWithName method to avoid obfuscated filename leakage from FileEntry.file() method
https://bugs.webkit.org/show_bug.cgi?id=61155

Covered by existing tests: fast/filesystem/file-from-file-entry.html

fast/filesystem/workers/file-from-file-entry.html
fast/filesystem/workers/file-from-file-entry-sync.html

  • fileapi/DOMFileSystem.cpp: (WebCore::DOMFileSystem::createFile): Updated to call createWithName().
  • fileapi/DOMFileSystemSync.cpp: (WebCore::DOMFileSystemSync::createFile): Updated to call createWithName().
  • fileapi/File.cpp: (WebCore::createBlobDataForFile): Added an optional name argument to fix MIME type lookup. (WebCore::File::createWithRelativePath): Renamed from create() for consistency with new method. (WebCore::File::File):
  • fileapi/File.h: (WebCore::File::createWithName):
  • html/FileInputType.cpp: (WebCore::FileInputType::setFileList): Updated the single caller of File::createWithRelativePath().
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r87094 r87095  
     12011-05-23  Adam Klein  <adamk@chromium.org>
     2
     3        Reviewed by Jian Li.
     4
     5        [fileapi] Add a File::createWithName method to avoid obfuscated filename leakage from FileEntry.file() method
     6        https://bugs.webkit.org/show_bug.cgi?id=61155
     7
     8        Covered by existing tests: fast/filesystem/file-from-file-entry.html
     9                                   fast/filesystem/workers/file-from-file-entry.html
     10                                   fast/filesystem/workers/file-from-file-entry-sync.html
     11
     12        * fileapi/DOMFileSystem.cpp:
     13        (WebCore::DOMFileSystem::createFile): Updated to call createWithName().
     14        * fileapi/DOMFileSystemSync.cpp:
     15        (WebCore::DOMFileSystemSync::createFile): Updated to call createWithName().
     16        * fileapi/File.cpp:
     17        (WebCore::createBlobDataForFile): Added an optional name argument to fix MIME type lookup.
     18        (WebCore::File::createWithRelativePath): Renamed from create() for consistency with new method.
     19        (WebCore::File::File):
     20        * fileapi/File.h:
     21        (WebCore::File::createWithName):
     22        * html/FileInputType.cpp:
     23        (WebCore::FileInputType::setFileList): Updated the single caller of File::createWithRelativePath().
     24
    1252011-05-23  Adrienne Walker  <enne@google.com>
    226
  • trunk/Source/WebCore/fileapi/DOMFileSystem.cpp

    r86325 r87095  
    118118class GetPathCallback : public FileSystemCallbacksBase {
    119119public:
    120     static PassOwnPtr<GetPathCallback> create(PassRefPtr<DOMFileSystem> filesystem, const String& path, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
     120    static PassOwnPtr<GetPathCallback> create(PassRefPtr<DOMFileSystem> filesystem, const String& path, const String& name, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
    121121    {
    122         return adoptPtr(new GetPathCallback(filesystem, path, successCallback, errorCallback));
     122        return adoptPtr(new GetPathCallback(filesystem, path, name, successCallback, errorCallback));
    123123    }
    124124
     
    128128            m_path = metadata.platformPath;
    129129
    130         m_filesystem->scheduleCallback(m_successCallback.release(), File::create(m_path));
     130        m_filesystem->scheduleCallback(m_successCallback.release(), File::createWithName(m_path, m_name));
    131131    }
    132132
    133133private:
    134     GetPathCallback(PassRefPtr<DOMFileSystem> filesystem, const String& path, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
     134    GetPathCallback(PassRefPtr<DOMFileSystem> filesystem, const String& path, const String& name, PassRefPtr<FileCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
    135135        : FileSystemCallbacksBase(errorCallback)
    136136        , m_filesystem(filesystem)
    137137        , m_path(path)
     138        , m_name(name)
    138139        , m_successCallback(successCallback)
    139140    {
     
    142143    RefPtr<DOMFileSystem> m_filesystem;
    143144    String m_path;
     145    String m_name;
    144146    RefPtr<FileCallback> m_successCallback;
    145147};
     
    151153    String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath());
    152154
    153     m_asyncFileSystem->readMetadata(platformPath, GetPathCallback::create(this, platformPath, successCallback, errorCallback));
     155    m_asyncFileSystem->readMetadata(platformPath, GetPathCallback::create(this, platformPath, fileEntry->name(), successCallback, errorCallback));
    154156}
    155157
  • trunk/Source/WebCore/fileapi/DOMFileSystemSync.cpp

    r81599 r87095  
    170170    if (!result->m_path.isEmpty())
    171171        platformPath = result->m_path;
    172     return File::create(platformPath);
     172    return File::createWithName(platformPath, fileEntry->name());
    173173}
    174174
  • trunk/Source/WebCore/fileapi/File.cpp

    r74380 r87095  
    3434namespace WebCore {
    3535
    36 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path)
     36static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, const String& name = String())
    3737{
    3838    String type;
    39     int index = path.reverseFind('.');
     39    const String& nameForMIMEType = !name.isEmpty() ? name : path;
     40    int index = nameForMIMEType.reverseFind('.');
    4041    if (index != -1)
    41         type = MIMETypeRegistry::getMIMETypeForExtension(path.substring(index + 1));
     42        type = MIMETypeRegistry::getMIMETypeForExtension(nameForMIMEType.substring(index + 1));
    4243
    4344    OwnPtr<BlobData> blobData = BlobData::create();
     
    4647    return blobData.release();
    4748}
     49
     50#if ENABLE(DIRECTORY_UPLOAD)
     51PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
     52{
     53    RefPtr<File> file = adoptRef(new File(path));
     54    file->m_relativePath = relativePath;
     55    return file.release();
     56}
     57#endif
    4858
    4959File::File(const String& path)
     
    6171}
    6272
    63 #if ENABLE(DIRECTORY_UPLOAD)
    64 File::File(const String& relativePath, const String& path)
    65     : Blob(createBlobDataForFile(path), -1)
     73#if ENABLE(FILE_SYSTEM)
     74File::File(const String& path, const String& name)
     75    : Blob(createBlobDataForFile(path, name), -1)
    6676    , m_path(path)
    67     , m_relativePath(relativePath)
     77    , m_name(name)
    6878{
    69     m_name = pathGetFileName(path);
    7079}
    7180#endif
  • trunk/Source/WebCore/fileapi/File.h

    r74380 r87095  
    5050
    5151#if ENABLE(DIRECTORY_UPLOAD)
    52     static PassRefPtr<File> create(const String& relativePath, const String& path)
     52    static PassRefPtr<File> createWithRelativePath(const String& path, const String& relativePath);
     53#endif
     54
     55#if ENABLE(FILE_SYSTEM)
     56    // Create a file with a name exposed to the author (via File.name and associated DOM properties) that differs from the one provided in the path.
     57    static PassRefPtr<File> createWithName(const String& path, const String& name)
    5358    {
    54         return adoptRef(new File(relativePath, path));
     59        return adoptRef(new File(path, name));
    5560    }
    5661#endif
     
    7681private:
    7782    File(const String& path);
    78    
     83
    7984    // For deserialization.
    8085    File(const String& path, const KURL& srcURL, const String& type);
    8186
    82 #if ENABLE(DIRECTORY_UPLOAD)
    83     File(const String& relativePath, const String& path);
     87#if ENABLE(FILE_SYSTEM)
     88    File(const String& path, const String& name);
    8489#endif
    8590
  • trunk/Source/WebCore/html/FileInputType.cpp

    r74895 r87095  
    179179            // Normalize backslashes to slashes before exposing the relative path to script.
    180180            String relativePath = paths[i].substring(1 + rootPath.length()).replace('\\', '/');
    181             m_fileList->append(File::create(relativePath, paths[i]));
     181            m_fileList->append(File::createWithRelativePath(paths[i], relativePath));
    182182        }
    183183        return;
Note: See TracChangeset for help on using the changeset viewer.