Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
graphql_compose_preview
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
graphql_compose_preview
Commits
fde02516
Commit
fde02516
authored
1 year ago
by
Al Munnings
Browse files
Options
Downloads
Patches
Plain Diff
Qualify the collection on the queries, ensure search is against preview_token in serialize
parent
2ff7dae2
No related branches found
No related tags found
No related merge requests found
Pipeline
#141243
passed
1 year ago
Stage: build
Stage: validate
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/KeyValueStore/DatabaseStorageExpirableToken.php
+21
-9
21 additions, 9 deletions
src/KeyValueStore/DatabaseStorageExpirableToken.php
with
21 additions
and
9 deletions
src/KeyValueStore/DatabaseStorageExpirableToken.php
+
21
−
9
View file @
fde02516
...
@@ -23,6 +23,21 @@ class DatabaseStorageExpirableToken extends DatabaseStorageExpirable {
...
@@ -23,6 +23,21 @@ class DatabaseStorageExpirableToken extends DatabaseStorageExpirable {
return
parent
::
doSetWithExpire
(
$key
,
$value
,
$expire
);
return
parent
::
doSetWithExpire
(
$key
,
$value
,
$expire
);
}
}
/**
* Escape the token value for searching within a serialized blob.
*
* @param string|null $token
* The token to escape.
*
* @return string
* The escaped token.
*/
protected
function
escapeToken
(
?string
$token
):
string
{
$token
=
$token
?:
''
;
$token
=
preg_replace
(
'/[^a-zA-Z0-9_-]/'
,
''
,
$token
);
return
sprintf
(
'%%;s:13:"preview_token";s:%d:"%s";%%'
,
strlen
(
$token
),
$token
);
}
/**
/**
* Load by token.
* Load by token.
*
*
...
@@ -33,14 +48,12 @@ class DatabaseStorageExpirableToken extends DatabaseStorageExpirable {
...
@@ -33,14 +48,12 @@ class DatabaseStorageExpirableToken extends DatabaseStorageExpirable {
* The value.
* The value.
*/
*/
public
function
getKeyByToken
(
?string
$token
)
{
public
function
getKeyByToken
(
?string
$token
)
{
$token_length
=
strlen
(
$token
??
''
);
$token_pattern
=
sprintf
(
'%%s:%s:"%s";%%'
,
$token_length
,
$token
);
try
{
try
{
return
$this
->
connection
->
query
(
return
$this
->
connection
->
query
(
'SELECT [name] FROM {'
.
$this
->
connection
->
escapeTable
(
$this
->
table
)
.
'} WHERE value LIKE :token'
,
'SELECT [name] FROM {'
.
$this
->
connection
->
escapeTable
(
$this
->
table
)
.
'} WHERE value LIKE :token
AND collection = :collection
'
,
[
[
':token'
=>
$token_pattern
,
':token'
=>
$this
->
escapeToken
(
$token
),
':collection'
=>
$this
->
collection
,
])
->
fetchField
();
])
->
fetchField
();
}
}
catch
(
\Exception
$e
)
{
catch
(
\Exception
$e
)
{
...
@@ -61,14 +74,13 @@ class DatabaseStorageExpirableToken extends DatabaseStorageExpirable {
...
@@ -61,14 +74,13 @@ class DatabaseStorageExpirableToken extends DatabaseStorageExpirable {
public
function
getTokenByKey
(
$name
)
{
public
function
getTokenByKey
(
$name
)
{
try
{
try
{
$preview_blob
=
$this
->
connection
->
query
(
$preview_blob
=
$this
->
connection
->
query
(
'SELECT [value] FROM {'
.
$this
->
connection
->
escapeTable
(
$this
->
table
)
.
'} WHERE name = :name'
,
'SELECT [value] FROM {'
.
$this
->
connection
->
escapeTable
(
$this
->
table
)
.
'} WHERE name = :name
AND collection = :collection
'
,
[
[
':name'
=>
$name
,
':name'
=>
$name
,
':collection'
=>
$this
->
collection
,
])
->
fetchField
();
])
->
fetchField
();
$preview_object
=
$this
->
serializer
->
decode
(
$preview_blob
);
return
$this
->
serializer
->
decode
(
$preview_blob
)
?->
preview_token
??
NULL
;
return
$preview_object
?->
preview_token
??
NULL
;
}
}
catch
(
\Exception
$e
)
{
catch
(
\Exception
$e
)
{
$this
->
catchException
(
$e
);
$this
->
catchException
(
$e
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment