Skip to content

Commit

Permalink
Merge pull request #526 from creative-commoners/pulls/4.1/revert
Browse files Browse the repository at this point in the history
[CVE-2023-28104] Revert schema rebuild
  • Loading branch information
GuySartorelli authored Mar 15, 2023
2 parents fadb1b2 + 4824085 commit 1d360f2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
29 changes: 1 addition & 28 deletions src/Schema/Storage/AbstractTypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
use GraphQL\Type\Definition\ListOfType;
use Exception;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\GraphQL\Schema\SchemaBuilder;
use SilverStripe\GraphQL\Schema\Exception\EmptySchemaException;
use SilverStripe\Control\Controller;
use SilverStripe\GraphQL\Controller as GraphQLController;

abstract class AbstractTypeRegistry
{
Expand All @@ -25,30 +21,7 @@ abstract class AbstractTypeRegistry
*/
public static function get(string $typename)
{
try {
return static::fromCache($typename);
} catch (Exception $e) {
if (!Controller::has_curr() ||
!(Controller::curr() instanceof GraphQLController) ||
!Controller::curr()->autobuildEnabled()
) {
throw $e;
}
// Try to rebuild the whole schema as fallback.
// This is to solve mysterious edge cases where schema files do not exist when they should.
// These edge cases are more likely on multi-server environments
$dirParts = explode(DIRECTORY_SEPARATOR, static::getSourceDirectory());
$key = $dirParts[count($dirParts) - 1];
$builder = SchemaBuilder::singleton();
$schema = $builder->boot($key);
try {
$builder->build($schema, true);
} catch (EmptySchemaException $e) {
// noop
}
// Attempt to return again now the schema has been rebuilt.
return static::fromCache($typename);
}
return static::fromCache($typename);
}

abstract protected static function getSourceDirectory(): string;
Expand Down
2 changes: 0 additions & 2 deletions tests/Schema/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,6 @@ private function createSchema(TestSchemaBuilder $factory): Schema

// Register as the default SchemaBuilder so that any calls to
// SchemaBuidler::singleton() get this TestSchemaBuilder
// This is important for the call in AbstractTypeRegisty::get() because
// otherwise a duplicate .graphql-generated folder will be created
Injector::inst()->registerService($factory, SchemaBuilder::class);

return $schema;
Expand Down

0 comments on commit 1d360f2

Please sign in to comment.