2024-02-04T08:35:09.694Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
324a0589-cc1c-48f0-b3a8-94b228a4176f
a79b2c2d364fbe68f9e849adbfcf49928fad973a9b5e2684f6771f58d9aab741
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
Security is a critical concern for any web application.
A secure app must prevent unauthorized database operations as well as validate the integrity of incoming data.
Firebase allows you to define database security logic in a JSON file that corresponds to the structure of your database.
A NoSQL database is essentially just a series of nodes, auths, and each node can have its own validation and security rules.
For example, you might have some data that's accessible to everybody that visits the site, or you might have some data that should only be accessed by authenticated users or other data that's only accessible the user that created it.
In this lesson, I'm gonna go through all these different scenarios and show you how to implement these as Firebase database rules.
Op you can define Firebase rules directly from your Angular project or from the Firebase console.
Personally, I prefer using the Firebase console because you can send test requests opt to make sure that your rules are working properly.
There are 3 types of rules you can set, read, write, and validate.
Read controls access off to data, write controls the ability to create, edit, or delete data, and validate controls the format of data.
Auth.
You can use any combination of these rules together or none of them at all.
There's also a series of variables that give you access to Firebase resources.
Auth.
Auth gives you access to the user authentication state.
Root gives you access to the root node of the database.
Op data gives you access to the data as it appears before the operation takes place.
New data shows you how The data will appear after an operation takes place.
Now gives you the UNIX timestamp for the current time.
Op there is also a wildcard variable that you can use to reference any child key throughout the database.
Now let's run through some of the most common security scenarios that you might run into.
1st, we can just disable all security so anybody can read or write to the database.
Op we can put everything on lockdown to where nobody can read or write to the database.
We can limit access to only authenticated users who are currently logged in.
Op we can also limit users' access to only content that they created.
Um, we do this by using the wildcard auth variable that we talked about earlier.
Um, in this case, we have some data nested under a user ID so we can then reference that user ID to make sure it matches the current auth ID of the logged in user.
In this example, we're only going to allow users who have been flagged as moderators to write data to the database.
We do this by first setting a moderator variable to true somewhere else in the database.
Then we use the root variable to traversed to wherever that point is.
You can also use Firebase rules to validate the integrity or format of incoming data.
Op in this case, I'm validating that some input is a string and that it's at least one character long but less offhand or equal to a 140 characters.
The now variable allows you to validate whether some data falls within a certain time frame.
In this case, we're checking to make sure a post doesn't have a time stamp that falls at a future time.
Op you can validate that new data has certain child attributes by calling the get children function and then passing it an array of the attributes that you wanna check.
Lastly, you can validate the existence or the nonexistence of data before performing some kind of operation.
This is useful because it allows you to control whether or not a user can create, update or delete some data.
A common pitfall with Firebase rules is that once you grant access to a resource, It can't be revoked somewhere further down the tree.
So you always wanna on the side of caution and only grant access when a specific set of conditions have been met.
So in this example, you can see that we granted access initially, but then op try to deny access later in the tree to only authenticated users.
When we run a test to this rule, we see that it op fails, and it grants access to the user that should not have access.
So when we reverse this around and deny offices initially.
We can see that the rule then does work when we send the corresponding request.
Op that's it for database rules.
Thanks for watching.

Speaker 0: Security is a critical concern for any web application. A secure app must prevent unauthorized database operations as well as validate the integrity of incoming data. Firebase allows you to define database security logic in a JSON file that corresponds to the structure of your database. A NoSQL database is essentially just a series of nodes, auths, and each node can have its own validation and security rules. For example, you might have some data that's accessible to everybody that visits the site, or you might have some data that should only be accessed by authenticated users or other data that's only accessible the user that created it.

In this lesson, I'm gonna go through all these different scenarios and show you how to implement these as Firebase database rules. Op you can define Firebase rules directly from your Angular project or from the Firebase console. Personally, I prefer using the Firebase console because you can send test requests opt to make sure that your rules are working properly. There are 3 types of rules you can set, read, write, and validate. Read controls access off to data, write controls the ability to create, edit, or delete data, and validate controls the format of data.

Auth. You can use any combination of these rules together or none of them at all. There's also a series of variables that give you access to Firebase resources. Auth. Auth gives you access to the user authentication state.

Root gives you access to the root node of the database. Op data gives you access to the data as it appears before the operation takes place. New data shows you how The data will appear after an operation takes place. Now gives you the UNIX timestamp for the current time. Op there is also a wildcard variable that you can use to reference any child key throughout the database.

Now let's run through some of the most common security scenarios that you might run into. 1st, we can just disable all security so anybody can read or write to the database. Op we can put everything on lockdown to where nobody can read or write to the database. We can limit access to only authenticated users who are currently logged in. Op we can also limit users' access to only content that they created.

Um, we do this by using the wildcard auth variable that we talked about earlier. Um, in this case, we have some data nested under a user ID so we can then reference that user ID to make sure it matches the current auth ID of the logged in user. In this example, we're only going to allow users who have been flagged as moderators to write data to the database. We do this by first setting a moderator variable to true somewhere else in the database. Then we use the root variable to traversed to wherever that point is.

You can also use Firebase rules to validate the integrity or format of incoming data. Op in this case, I'm validating that some input is a string and that it's at least one character long but less offhand or equal to a 140 characters. The now variable allows you to validate whether some data falls within a certain time frame. In this case, we're checking to make sure a post doesn't have a time stamp that falls at a future time. Op you can validate that new data has certain child attributes by calling the get children function and then passing it an array of the attributes that you wanna check.

Lastly, you can validate the existence or the nonexistence of data before performing some kind of operation. This is useful because it allows you to control whether or not a user can create, update or delete some data. A common pitfall with Firebase rules is that once you grant access to a resource, It can't be revoked somewhere further down the tree. So you always wanna on the side of caution and only grant access when a specific set of conditions have been met. So in this example, you can see that we granted access initially, but then op try to deny access later in the tree to only authenticated users.

When we run a test to this rule, we see that it op fails, and it grants access to the user that should not have access. So when we reverse this around and deny offices initially. We can see that the rule then does work when we send the corresponding request. Op that's it for database rules. Thanks for watching.
Security is a critical concern for any web application. A secure app must prevent unauthorized database operations as well as validate the integrity of incoming data. Firebase allows you to define database security logic in a JSON file that corresponds to the structure of your database. A NoSQL database is essentially just a series of nodes, auths, and each node can have its own validation and security rules. For example, you might have some data that's accessible to everybody that visits the site, or you might have some data that should only be accessed by authenticated users or other data that's only accessible the user that created it. In this lesson, I'm gonna go through all these different scenarios and show you how to implement these as Firebase database rules.
databases
security
data management
data
Op you can define Firebase rules directly from your Angular project or from the Firebase console. Personally, I prefer using the Firebase console because you can send test requests opt to make sure that your rules are working properly. There are 3 types of rules you can set, read, write, and validate.
Read controls access off to data, write controls the ability to create, edit, or delete data, and validate controls the format of data. Auth. You can use any combination of these rules together or none of them at all. There's also a series of variables that give you access to Firebase resources.
data
Auth. Auth gives you access to the user authentication state. Root gives you access to the root node of the database.
Op data gives you access to the data as it appears before the operation takes place. New data shows you how The data will appear after an operation takes place. Now gives you the UNIX timestamp for the current time. Op there is also a wildcard variable that you can use to reference any child key throughout the database.
data
Now let's run through some of the most common security scenarios that you might run into. 1st, we can just disable all security so anybody can read or write to the database. Op we can put everything on lockdown to where nobody can read or write to the database. We can limit access to only authenticated users who are currently logged in.
security
databases
Op we can also limit users' access to only content that they created. Um, we do this by using the wildcard auth variable that we talked about earlier.
Um, in this case, we have some data nested under a user ID so we can then reference that user ID to make sure it matches the current auth ID of the logged in user. In this example, we're only going to allow users who have been flagged as moderators to write data to the database. We do this by first setting a moderator variable to true somewhere else in the database. Then we use the root variable to traversed to wherever that point is.
databases
data management
data
You can also use Firebase rules to validate the integrity or format of incoming data. Op in this case, I'm validating that some input is a string and that it's at least one character long but less offhand or equal to a 140 characters.
The now variable allows you to validate whether some data falls within a certain time frame. In this case, we're checking to make sure a post doesn't have a time stamp that falls at a future time. Op you can validate that new data has certain child attributes by calling the get children function and then passing it an array of the attributes that you wanna check. Lastly, you can validate the existence or the nonexistence of data before performing some kind of operation. This is useful because it allows you to control whether or not a user can create, update or delete some data.
data
A common pitfall with Firebase rules is that once you grant access to a resource, It can't be revoked somewhere further down the tree. So you always wanna on the side of caution and only grant access when a specific set of conditions have been met. So in this example, you can see that we granted access initially, but then op try to deny access later in the tree to only authenticated users.
security
When we run a test to this rule, we see that it op fails, and it grants access to the user that should not have access. So when we reverse this around and deny offices initially. We can see that the rule then does work when we send the corresponding request.
Op that's it for database rules. Thanks for watching.
Security is a critical concern for any web application. A secure app must prevent unauthorized database operations as well as validate the integrity of incoming data. Firebase allows you to define database security logic in a JSON file that corresponds to the structure of your database. A NoSQL database is essentially just a series of nodes, auths, and each node can have its own validation and security rules. For example, you might have some data that's accessible to everybody that visits the site, or you might have some data that should only be accessed by authenticated users or other data that's only accessible the user that created it. In this lesson, I'm gonna go through all these different scenarios and show you how to implement these as Firebase database rules. Op you can define Firebase rules directly from your Angular project or from the Firebase console. Personally, I prefer using the Firebase console because you can send test requests opt to make sure that your rules are working properly. There are 3 types of rules you can set, read, write, and validate. Read controls access off to data, write controls the ability to create, edit, or delete data, and validate controls the format of data. Auth. You can use any combination of these rules together or none of them at all. There's also a series of variables that give you access to Firebase resources. Auth. Auth gives you access to the user authentication state. Root gives you access to the root node of the database. Op data gives you access to the data as it appears before the operation takes place. New data shows you how The data will appear after an operation takes place. Now gives you the UNIX timestamp for the current time. Op there is also a wildcard variable that you can use to reference any child key throughout the database. Now let's run through some of the most common security scenarios that you might run into. 1st, we can just disable all security so anybody can read or write to the database. Op we can put everything on lockdown to where nobody can read or write to the database. We can limit access to only authenticated users who are currently logged in. Op we can also limit users' access to only content that they created. Um, we do this by using the wildcard auth variable that we talked about earlier. Um, in this case, we have some data nested under a user ID so we can then reference that user ID to make sure it matches the current auth ID of the logged in user. In this example, we're only going to allow users who have been flagged as moderators to write data to the database. We do this by first setting a moderator variable to true somewhere else in the database. Then we use the root variable to traversed to wherever that point is. You can also use Firebase rules to validate the integrity or format of incoming data. Op in this case, I'm validating that some input is a string and that it's at least one character long but less offhand or equal to a 140 characters. The now variable allows you to validate whether some data falls within a certain time frame. In this case, we're checking to make sure a post doesn't have a time stamp that falls at a future time. Op you can validate that new data has certain child attributes by calling the get children function and then passing it an array of the attributes that you wanna check. Lastly, you can validate the existence or the nonexistence of data before performing some kind of operation. This is useful because it allows you to control whether or not a user can create, update or delete some data. A common pitfall with Firebase rules is that once you grant access to a resource, It can't be revoked somewhere further down the tree. So you always wanna on the side of caution and only grant access when a specific set of conditions have been met. So in this example, you can see that we granted access initially, but then op try to deny access later in the tree to only authenticated users. When we run a test to this rule, we see that it op fails, and it grants access to the user that should not have access. So when we reverse this around and deny offices initially. We can see that the rule then does work when we send the corresponding request. Op that's it for database rules. Thanks for watching.
Security
security
is
is
a
a
critical
critical
concern
concern
for
for
any
any
web
web
application.
application
A
a
secure
secure
app
app
must
must
prevent
prevent
unauthorized
unauthorized
database
database
operations
operations
as
as
well
well
as
as
validate
validate
the
the
integrity
integrity
of
of
incoming
incoming
data.
data
Firebase
firebase
allows
allows
you
you
to
to
define
define
database
database
security
security
logic
logic
in
in
a
a
JSON
json
file
file
that
that
corresponds
corresponds
to
to
the
the
structure
structure
of
of
your
your
database.
database
A
a
NoSQL
nosql
database
database
is
is
essentially
essentially
just
just
a
a
series
series
of
of
nodes,
nodes
auths,
auths
and
and
each
each
node
node
can
can
have
have
its
its
own
own
validation
validation
and
and
security
security
rules.
rules
For
for
example,
example
you
you
might
might
have
have
some
some
data
data
that's
that's
accessible
accessible
to
to
everybody
everybody
that
that
visits
visits
the
the
site,
site
or
or
you
you
might
might
have
have
some
some
data
data
that
that
should
should
only
only
be
be
accessed
accessed
by
by
authenticated
authenticated
users
users
or
or
other
other
data
data
that's
that's
only
only
accessible
accessible
the
the
user
user
that
that
created
created
it.
it
In
in
this
this
lesson,
lesson
I'm
i'm
gonna
gonna
go
go
through
through
all
all
these
these
different
different
scenarios
scenarios
and
and
show
show
you
you
how
how
to
to
implement
implement
these
these
as
as
Firebase
firebase
database
database
rules.
rules
Op
op
you
you
can
can
define
define
Firebase
firebase
rules
rules
directly
directly
from
from
your
your
Angular
angular
project
project
or
or
from
from
the
the
Firebase
firebase
console.
console
Personally,
personally
I
i
prefer
prefer
using
using
the
the
Firebase
firebase
console
console
because
because
you
you
can
can
send
send
test
test
requests
requests
opt
opt
to
to
make
make
sure
sure
that
that
your
your
rules
rules
are
are
working
working
properly.
properly
There
there
are
are
3
3
types
types
of
of
rules
rules
you
you
can
can
set,
set
read,
read
write,
write
and
and
validate.
validate
Read
read
controls
controls
access
access
off
off
to
to
data,
data
write
write
controls
controls
the
the
ability
ability
to
to
create,
create
edit,
edit
or
or
delete
delete
data,
data
and
and
validate
validate
controls
controls
the
the
format
format
of
of
data.
data
Auth.
auth
You
you
can
can
use
use
any
any
combination
combination
of
of
these
these
rules
rules
together
together
or
or
none
none
of
of
them
them
at
at
all.
all
There's
there's
also
also
a
a
series
series
of
of
variables
variables
that
that
give
give
you
you
access
access
to
to
Firebase
firebase
resources.
resources
Auth.
auth
Auth
auth
gives
gives
you
you
access
access
to
to
the
the
user
user
authentication
authentication
state.
state
Root
root
gives
gives
you
you
access
access
to
to
the
the
root
root
node
node
of
of
the
the
database.
database
Op
op
data
data
gives
gives
you
you
access
access
to
to
the
the
data
data
as
as
it
it
appears
appears
before
before
the
the
operation
operation
takes
takes
place.
place
New
new
data
data
shows
shows
you
you
how
how
The
the
data
data
will
will
appear
appear
after
after
an
an
operation
operation
takes
takes
place.
place
Now
now
gives
gives
you
you
the
the
UNIX
unix
timestamp
timestamp
for
for
the
the
current
current
time.
time
Op
op
there
there
is
is
also
also
a
a
wildcard
wildcard
variable
variable
that
that
you
you
can
can
use
use
to
to
reference
reference
any
any
child
child
key
key
throughout
throughout
the
the
database.
database
Now
now
let's
let's
run
run
through
through
some
some
of
of
the
the
most
most
common
common
security
security
scenarios
scenarios
that
that
you
you
might
might
run
run
into.
into
1st,
1st
we
we
can
can
just
just
disable
disable
all
all
security
security
so
so
anybody
anybody
can
can
read
read
or
or
write
write
to
to
the
the
database.
database
Op
op
we
we
can
can
put
put
everything
everything
on
on
lockdown
lockdown
to
to
where
where
nobody
nobody
can
can
read
read
or
or
write
write
to
to
the
the
database.
database
We
we
can
can
limit
limit
access
access
to
to
only
only
authenticated
authenticated
users
users
who
who
are
are
currently
currently
logged
logged
in.
in
Op
op
we
we
can
can
also
also
limit
limit
users'
users'
access
access
to
to
only
only
content
content
that
that
they
they
created.
created
Um,
um
we
we
do
do
this
this
by
by
using
using
the
the
wildcard
wildcard
auth
auth
variable
variable
that
that
we
we
talked
talked
about
about
earlier.
earlier
Um,
um
in
in
this
this
case,
case
we
we
have
have
some
some
data
data
nested
nested
under
under
a
a
user
user
ID
id
so
so
we
we
can
can
then
then
reference
reference
that
that
user
user
ID
id
to
to
make
make
sure
sure
it
it
matches
matches
the
the
current
current
auth
auth
ID
id
of
of
the
the
logged
logged
in
in
user.
user
In
in
this
this
example,
example
we're
we're
only
only
going
going
to
to
allow
allow
users
users
who
who
have
have
been
been
flagged
flagged
as
as
moderators
moderators
to
to
write
write
data
data
to
to
the
the
database.
database
We
we
do
do
this
this
by
by
first
first
setting
setting
a
a
moderator
moderator
variable
variable
to
to
true
true
somewhere
somewhere
else
else
in
in
the
the
database.
database
Then
then
we
we
use
use
the
the
root
root
variable
variable
to
to
traversed
traversed
to
to
wherever
wherever
that
that
point
point
is.
is
You
you
can
can
also
also
use
use
Firebase
firebase
rules
rules
to
to
validate
validate
the
the
integrity
integrity
or
or
format
format
of
of
incoming
incoming
data.
data
Op
op
in
in
this
this
case,
case
I'm
i'm
validating
validating
that
that
some
some
input
input
is
is
a
a
string
string
and
and
that
that
it's
it's
at
at
least
least
one
one
character
character
long
long
but
but
less
less
offhand
offhand
or
or
equal
equal
to
to
a
a
140
140
characters.
characters
The
the
now
now
variable
variable
allows
allows
you
you
to
to
validate
validate
whether
whether
some
some
data
data
falls
falls
within
within
a
a
certain
certain
time
time
frame.
frame
In
in
this
this
case,
case
we're
we're
checking
checking
to
to
make
make
sure
sure
a
a
post
post
doesn't
doesn't
have
have
a
a
time
time
stamp
stamp
that
that
falls
falls
at
at
a
a
future
future
time.
time
Op
op
you
you
can
can
validate
validate
that
that
new
new
data
data
has
has
certain
certain
child
child
attributes
attributes
by
by
calling
calling
the
the
get
get
children
children
function
function
and
and
then
then
passing
passing
it
it
an
an
array
array
of
of
the
the
attributes
attributes
that
that
you
you
wanna
wanna
check.
check
Lastly,
lastly
you
you
can
can
validate
validate
the
the
existence
existence
or
or
the
the
nonexistence
nonexistence
of
of
data
data
before
before
performing
performing
some
some
kind
kind
of
of
operation.
operation
This
this
is
is
useful
useful
because
because
it
it
allows
allows
you
you
to
to
control
control
whether
whether
or
or
not
not
a
a
user
user
can
can
create,
create
update
update
or
or
delete
delete
some
some
data.
data
A
a
common
common
pitfall
pitfall
with
with
Firebase
firebase
rules
rules
is
is
that
that
once
once
you
you
grant
grant
access
access
to
to
a
a
resource,
resource
It
it
can't
can't
be
be
revoked
revoked
somewhere
somewhere
further
further
down
down
the
the
tree.
tree
So
so
you
you
always
always
wanna
wanna
on
on
the
the
side
side
of
of
caution
caution
and
and
only
only
grant
grant
access
access
when
when
a
a
specific
specific
set
set
of
of
conditions
conditions
have
have
been
been
met.
met
So
so
in
in
this
this
example,
example
you
you
can
can
see
see
that
that
we
we
granted
granted
access
access
initially,
initially
but
but
then
then
op
op
try
try
to
to
deny
deny
access
access
later
later
in
in
the
the
tree
tree
to
to
only
only
authenticated
authenticated
users.
users
When
when
we
we
run
run
a
a
test
test
to
to
this
this
rule,
rule
we
we
see
see
that
that
it
it
op
op
fails,
fails
and
and
it
it
grants
grants
access
access
to
to
the
the
user
user
that
that
should
should
not
not
have
have
access.
access
So
so
when
when
we
we
reverse
reverse
this
this
around
around
and
and
deny
deny
offices
offices
initially.
initially
We
we
can
can
see
see
that
that
the
the
rule
rule
then
then
does
does
work
work
when
when
we
we
send
send
the
the
corresponding
corresponding
request.
request
Op
op
that's
that's
it
it
for
for
database
database
rules.
rules
Thanks
thanks
for
for
watching.
watching
success
In this video, the speaker discusses the use of obtain children function in obtain data for a web application. They explain the process of creating a database and validating its integrity through using the wildcard denies variable. The speaker also discusses the use of obtain children for checking data integrity and the potential risks of the use of obtain children in the future.
Firebase Database Rules Tutorial
https://angularfirebase.com/lessons/understanding-firebase-database-rules-by-example/

Learn how to use Firebase database rules by example.