Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 8399d6f5
authored
Jan 30, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix security issue with sequelize generated id attribute
1 parent
d02ac442
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
8 deletions
changelog.md
lib/dao-factory.js
lib/dao.js
test/dao/values.test.js
changelog.md
View file @
8399d6f
...
@@ -8,6 +8,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
...
@@ -8,6 +8,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
-
[
Feature
]
Support for HAVING queries.
[
#1286
](
https://github.com/sequelize/sequelize/pull/1286
)
-
[
Feature
]
Support for HAVING queries.
[
#1286
](
https://github.com/sequelize/sequelize/pull/1286
)
-
bulkUpdate and bulkDestroy now returns affected rows.
[
#1293
](
https://github.com/sequelize/sequelize/pull/1293
)
-
bulkUpdate and bulkDestroy now returns affected rows.
[
#1293
](
https://github.com/sequelize/sequelize/pull/1293
)
-
fixes transaction memory leak issue
-
fixes transaction memory leak issue
-
fixes security issue where it was possible to overwrite the id attribute when defined by sequelize (screwup - and fix - by mickhansen)
# v1.7.0-rc2
# v1.7.0-rc2
-
fixes unixSocket connections for mariadb
[
#1248
](
https://github.com/sequelize/sequelize/pull/1248
)
-
fixes unixSocket connections for mariadb
[
#1248
](
https://github.com/sequelize/sequelize/pull/1248
)
...
...
lib/dao-factory.js
View file @
8399d6f
...
@@ -164,7 +164,7 @@ module.exports = (function() {
...
@@ -164,7 +164,7 @@ module.exports = (function() {
this
.
DAO
.
prototype
.
_hasPrimaryKeys
=
this
.
options
.
hasPrimaryKeys
this
.
DAO
.
prototype
.
_hasPrimaryKeys
=
this
.
options
.
hasPrimaryKeys
this
.
DAO
.
prototype
.
_isPrimaryKey
=
Utils
.
_
.
memoize
(
function
(
key
)
{
this
.
DAO
.
prototype
.
_isPrimaryKey
=
Utils
.
_
.
memoize
(
function
(
key
)
{
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
return
self
.
primaryKeyAttributes
.
indexOf
(
key
)
!==
-
1
&&
key
!==
'id'
})
})
if
(
this
.
options
.
timestamps
)
{
if
(
this
.
options
.
timestamps
)
{
...
...
lib/dao.js
View file @
8399d6f
...
@@ -170,6 +170,12 @@ module.exports = (function() {
...
@@ -170,6 +170,12 @@ module.exports = (function() {
return
return
}
}
// If attempting to set generated id and id is already defined, return
// This is hack since generated id is not in primaryKeys, although it should be
if
(
originalValue
&&
key
===
"id"
)
{
return
}
// If attempting to set read only attributes, return
// If attempting to set read only attributes, return
if
(
!
options
.
raw
&&
this
.
_hasReadOnlyAttributes
&&
this
.
_isReadOnlyAttribute
(
key
))
{
if
(
!
options
.
raw
&&
this
.
_hasReadOnlyAttributes
&&
this
.
_isReadOnlyAttribute
(
key
))
{
return
return
...
@@ -485,14 +491,13 @@ module.exports = (function() {
...
@@ -485,14 +491,13 @@ module.exports = (function() {
return
validator
.
hookValidate
()
return
validator
.
hookValidate
()
}
}
DAO
.
prototype
.
updateAttributes
=
function
(
updates
,
fieldsOrO
ptions
)
{
DAO
.
prototype
.
updateAttributes
=
function
(
updates
,
o
ptions
)
{
if
(
fieldsOrO
ptions
instanceof
Array
)
{
if
(
o
ptions
instanceof
Array
)
{
fieldsOrOptions
=
{
fields
:
fieldsOrO
ptions
}
options
=
{
fields
:
o
ptions
}
}
}
this
.
setAttributes
(
updates
)
this
.
set
(
updates
)
return
this
.
save
(
options
)
return
this
.
save
(
fieldsOrOptions
)
}
}
DAO
.
prototype
.
setAttributes
=
function
(
updates
)
{
DAO
.
prototype
.
setAttributes
=
function
(
updates
)
{
...
...
test/dao/values.test.js
View file @
8399d6f
...
@@ -17,7 +17,24 @@ chai.Assertion.includeStack = true
...
@@ -17,7 +17,24 @@ chai.Assertion.includeStack = true
describe
(
Support
.
getTestDialectTeaser
(
"DAO"
),
function
()
{
describe
(
Support
.
getTestDialectTeaser
(
"DAO"
),
function
()
{
describe
(
'Values'
,
function
()
{
describe
(
'Values'
,
function
()
{
describe
(
'set'
,
function
()
{
describe
(
'set'
,
function
()
{
it
(
'doesn\'t overwrite primary keys'
,
function
()
{
it
(
'doesn\'t overwrite generated primary keys'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
name
:
{
type
:
DataTypes
.
STRING
}
})
var
user
=
User
.
build
({
id
:
1
,
name
:
'Mick'
})
expect
(
user
.
get
(
'id'
)).
to
.
equal
(
1
)
expect
(
user
.
get
(
'name'
)).
to
.
equal
(
'Mick'
)
user
.
set
({
id
:
2
,
name
:
'Jan'
})
expect
(
user
.
get
(
'id'
)).
to
.
equal
(
1
)
expect
(
user
.
get
(
'name'
)).
to
.
equal
(
'Jan'
)
})
it
(
'doesn\'t overwrite defined primary keys'
,
function
()
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
var
User
=
this
.
sequelize
.
define
(
'User'
,
{
identifier
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
}
identifier
:
{
type
:
DataTypes
.
STRING
,
primaryKey
:
true
}
})
})
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment