⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 183646 in webkit


Ignore:
Timestamp:
Apr 30, 2015, 3:15:29 PM (11 years ago)
Author:
beidson@apple.com
Message:

Javascript using WebSQL can create their own WebKit info table.
<rdar://problem/20688792> and https://bugs.webkit.org/show_bug.cgi?id=144466

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/websql/alter-to-info-table.html

  • Modules/webdatabase/DatabaseBackendBase.cpp:

(WebCore::DatabaseBackendBase::databaseInfoTableName): Return the info table name.
(WebCore::fullyQualifiedInfoTableName): Append "main." to the info table name.
(WebCore::DatabaseBackendBase::DatabaseBackendBase): Use the fully qualified name.
(WebCore::DatabaseBackendBase::performOpenAndVerify): Ditto.
(WebCore::DatabaseBackendBase::getVersionFromDatabase): Ditto.
(WebCore::DatabaseBackendBase::setVersionInDatabase): Ditto.

LayoutTests:

  • storage/websql/alter-to-info-table-expected.txt: Added.
  • storage/websql/alter-to-info-table.html: Added.
  • storage/websql/alter-to-info-table.js: Added.
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r183644 r183646  
     12015-04-30  Brady Eidson  <beidson@apple.com>
     2
     3        Javascript using WebSQL can create their own WebKit info table.
     4        <rdar://problem/20688792> and https://bugs.webkit.org/show_bug.cgi?id=144466
     5
     6        Reviewed by Alex Christensen.
     7
     8        * storage/websql/alter-to-info-table-expected.txt: Added.
     9        * storage/websql/alter-to-info-table.html: Added.
     10        * storage/websql/alter-to-info-table.js: Added.
     11
    1122015-04-30  Martin Robinson  <mrobinson@igalia.com>
    213
  • trunk/LayoutTests/storage/websql/test-authorizer-expected.txt

    r117816 r183646  
    1616SQLITE_ALTER_TABLE statement succeeded.
    1717SQLITE_ALTER_TABLE statement succeeded.
     18SQLITE_ALTER_INFO_TABLE statement failed: could not prepare statement (23 not authorized)
     19SQLITE_ALTER_INFO_TABLE statement failed: could not prepare statement (23 not authorized)
     20SQLITE_ALTER_INFO_TABLE statement failed: could not prepare statement (1 there is already another table or index with this name: __WebKitDatabaseInfoTable__)
    1821SQLITE_TRANSACTION statement failed: could not prepare statement (23 not authorized)
    1922SQLITE_ATTACH statement failed: could not prepare statement (23 not authorized)
     
    5356SQLITE_ALTER_TABLE statement failed: could not prepare statement (23 not authorized)
    5457SQLITE_ALTER_TABLE statement failed: could not prepare statement (1 no such table: TestTable)
     58SQLITE_ALTER_INFO_TABLE statement failed: could not prepare statement (23 not authorized)
     59SQLITE_ALTER_INFO_TABLE statement failed: could not prepare statement (23 not authorized)
     60SQLITE_ALTER_INFO_TABLE statement failed: could not prepare statement (1 there is already another table or index with this name: __WebKitDatabaseInfoTable__)
    5561SQLITE_TRANSACTION statement failed: could not prepare statement (23 not authorized)
    5662SQLITE_ATTACH statement failed: could not prepare statement (23 not authorized)
  • trunk/LayoutTests/storage/websql/test-authorizer.js

    r120516 r183646  
    7373    // Rename the table back to its original name
    7474    executeStatement(tx, "ALTER TABLE TestTable RENAME To Test;", "SQLITE_ALTER_TABLE");
     75
     76    // These should always fail, as nobody gets to mess with the info table.
     77    executeStatement(tx, "ALTER TABLE __WebKitDatabaseInfoTable__ RENAME TO TestTable;", "SQLITE_ALTER_INFO_TABLE");
     78    executeStatement(tx, "ALTER TABLE main.__WebKitDatabaseInfoTable__ RENAME TO TestTable;", "SQLITE_ALTER_INFO_TABLE");
     79    executeStatement(tx, "ALTER TABLE Test RENAME TO __WebKitDatabaseInfoTable__;", "SQLITE_ALTER_INFO_TABLE");
    7580
    7681    executeStatement(tx, "BEGIN TRANSACTION;", "SQLITE_TRANSACTION");
  • trunk/Source/WebCore/ChangeLog

    r183645 r183646  
     12015-04-30  Brady Eidson  <beidson@apple.com>
     2
     3        Javascript using WebSQL can create their own WebKit info table.
     4        <rdar://problem/20688792> and https://bugs.webkit.org/show_bug.cgi?id=144466
     5
     6        Reviewed by Alex Christensen.
     7
     8        Test: storage/websql/alter-to-info-table.html
     9
     10        * Modules/webdatabase/DatabaseBackendBase.cpp:
     11        (WebCore::DatabaseBackendBase::databaseInfoTableName): Return the info table name.
     12        (WebCore::fullyQualifiedInfoTableName): Append "main." to the info table name.
     13        (WebCore::DatabaseBackendBase::DatabaseBackendBase): Use the fully qualified name.
     14        (WebCore::DatabaseBackendBase::performOpenAndVerify): Ditto.
     15        (WebCore::DatabaseBackendBase::getVersionFromDatabase): Ditto.
     16        (WebCore::DatabaseBackendBase::setVersionInDatabase): Ditto.
     17
    1182015-04-30  Beth Dakin  <bdakin@apple.com>
    219
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseBackendBase.cpp

    r182365 r183646  
    8383
    8484static const char versionKey[] = "WebKitDatabaseVersionKey";
    85 static const char infoTableName[] = "__WebKitDatabaseInfoTable__";
     85static const char unqualifiedInfoTableName[] = "__WebKitDatabaseInfoTable__";
     86
     87const char* DatabaseBackendBase::databaseInfoTableName()
     88{
     89    return unqualifiedInfoTableName;
     90}
     91
     92static const char* fullyQualifiedInfoTableName()
     93{
     94    static const char qualifier[] = "main.";
     95    static char qualifiedName[sizeof(qualifier) + sizeof(unqualifiedInfoTableName) - 1];
     96
     97    static std::once_flag onceFlag;
     98    std::call_once(onceFlag, []{
     99        char* newDestination = stpcpy(qualifiedName, qualifier);
     100        strcpy(newDestination, unqualifiedInfoTableName);
     101    });
     102
     103    return qualifiedName;
     104}
    86105
    87106static String formatErrorMessage(const char* message, int sqliteErrorCode, const char* sqliteErrorMessage)
     
    189208
    190209    return guid;
    191 }
    192 
    193 // static
    194 const char* DatabaseBackendBase::databaseInfoTableName()
    195 {
    196     return infoTableName;
    197210}
    198211
     
    215228    m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolatedCopy();
    216229
    217     m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName);
     230    m_databaseAuthorizer = DatabaseAuthorizer::create(unqualifiedInfoTableName);
    218231
    219232    if (m_name.isNull())
     
    345358            }
    346359
    347             String tableName(infoTableName);
     360            String tableName(unqualifiedInfoTableName);
    348361            if (!m_sqliteDatabase.tableExists(tableName)) {
    349362                m_new = true;
     
    444457bool DatabaseBackendBase::getVersionFromDatabase(String& version, bool shouldCacheVersion)
    445458{
    446     String query(String("SELECT value FROM ") + infoTableName +  " WHERE key = '" + versionKey + "';");
     459    String query(String("SELECT value FROM ") + fullyQualifiedInfoTableName() +  " WHERE key = '" + versionKey + "';");
    447460
    448461    m_databaseAuthorizer->disable();
     
    464477    // The INSERT will replace an existing entry for the database with the new version number, due to the UNIQUE ON CONFLICT REPLACE
    465478    // clause in the CREATE statement (see Database::performOpenAndVerify()).
    466     String query(String("INSERT INTO ") + infoTableName +  " (key, value) VALUES ('" + versionKey + "', ?);");
     479    String query(String("INSERT INTO ") + fullyQualifiedInfoTableName() +  " (key, value) VALUES ('" + versionKey + "', ?);");
    467480
    468481    m_databaseAuthorizer->disable();
Note: See TracChangeset for help on using the changeset viewer.