Firebase deployment error - deployment

I've deployed in the past many times before. For some reason, today I am getting this error I can't seem to fix. I've tried changing tabs out with 2 or 4 spaces. I've tried different formats, and nothing works.
Here's what it says:
Error: There was an error loading firebase.json
Trailing comma in object at 29:9
}
^
Here is my firebase.json
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public"
}
}
How do I solve it?
PS: If you need anything else please ask.

To anyone experiencing this problem, I solved mine by going to the file "database.rules.json", and removing the last comma in the line ".write": true,
{
"rules": {
".read": true,
".write": true,
}
}
It seems Firebase generated an invalid JSON.

Change your firebase json file to
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"rewrites": [
]
}
}
If you are still having issues then you also have to change your database file to
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}

This error is caused by invalid JSON format within database.rules.json file.
First, open a database.rules.json file.
move to the end of line in the file.
remove ',' at last position of the line.

This error means the JSON format of the database.json is invalid. Simply go to the line specified, 29 in your case, and remove the comma to make the JSON valid. JSON files do not allow trailing commas.

Check if your database.rules.json has valid json format.

In my case it was showing this error in firebase.json file but I didn't find any error there and so I checked databaserules.json file and shown error was there. I corrected it and it worked.

Related

realtime database rules wildcard

as soon as I use a wildcard I get this error:
Unhandled Exception: [firebase_database/permission-denied] Client doesn't have permission to access the desired data
works:
{
"rules": {
"user": {
".write": "auth != null",
".read": "auth != null"
}
}
doesn't work:
{
"rules": {
"user": {
"$userId": {
".write": "auth != null && $userId === auth.uid",
".read": "auth != null"
}
}
}
doesn't work:
{
"rules": {
"user": {
"$userId": {
".write": true,
".read": true
}
}
}
db structure:
code:
List<User>? userlist;
late Query query;
void initState() {
userAuth.FirebaseAuth.instance.authStateChanges().listen((userAuth.User? user) {
final FirebaseApp abcApp = Firebase.app();
final FirebaseDatabase database = FirebaseDatabase.instanceFor(app: abcApp);
userlist = [];
query = database
.ref().child("user").orderByChild("userId")
.equalTo(
ownUid==true
?user!.uid
:widget.peerId
);
_onOrderAddedSubscription1 = query.onChildAdded.listen(onEntryAdded1);
_onOrderChangedSubscription1 = query.onChildChanged.listen(onEntryChanged1);
});
super.initState();
}
My guess is that you're trying to read from /users. If you do that with the second set of rules, it gets rejected as those rules don't grant anyone permission to read all of /users - but only allows one to read /users/$uid.
It helps to recall that security rules on their own don't filter data, but instead merely check whether all data access is authorized.
So if you want to allow reading from /users, you need a rule on /users that allows that read. And if you want to allow reading specific data under /users, you either need to read from that specific path or combine a query and rules so that the rules can verify that the client is only reading data they're authorized for.
This problem comes up quite regularly, so I also recommend checking out more questions about 'rules are not filters'

How can I securely allow everyone to read and auth users to write to application with Firebase Realtime database?

I am building a social media application in which anyone can read what is going on but have to sign in to interact with each post. I would like to find a way to allow all my users to be able to do this without having an insecure database. I am almost done with development and I am currently trying to clean up a few things.
My current Rules are set to true for development purposes:
{
"rules": {
".read": true,
".write": true
}
}
I have tried a few rules
1.
{
"rules": {
"$uid": {
".read": true,
".write": "auth.uid == $uid"
}
}
}
Which allows everyone to read but doesn't allow writing due to permissions.
2)
{
"rules": {
"$uid": {
".read": "auth.uid == $uid",
".write": "auth.uid == $uid"
}
}
}
Which doesn't allow anyone to read or write due to permissions.
3.
{
"rules": {
".read": "auth.uid != null",
".write": "auth.uid != null"
}
}
Which works but I get an email later telling me my database is insecure.
Here is an example that causes a permission denied error:
A) When the user clicks the send new announcement button
This func is called.
StorageService.sendAnnouncementDataToDatabase(photoUrl: "", announcementComment: announcementComment, ratio: CGFloat(0), onSuccess: {
ProgressHUD.showSuccess("SWEET")
})
B) Inside sendAnnouncementDataToDatabase func
let ref = Ref().databaseAnnouncements
let newAnnouncementID = ref.childByAutoId().key ?? ""
let newAnnouncementReference = ref.child(newAnnouncementID)
guard let currentUser = Api.User.CURRENT_USER else {
return
}
var dict = ["userId" : currentUserId, "photoUrl" : photoUrl]
newAnnouncementReference.setValue(dict, withCompletionBlock: {(error,ref) in
// permission denied occurs here
})
I have read through many documents, and stack question. As well as tried to set rules for each path. Same outcome.
Any ideas would be helpful.
Thank you.
If this is the actual goal
in which anyone can read what is going on but have to sign in to
interact with each post
then this rule will do it
{
"rules": {
".read": true,
".write": "auth != null"
}
}
As it allows anyone to read anything, but only authenticated users can write.
However, it's pretty insecure as Frank mentioned in his comments. We may be able to expand on this solution a bit but without understanding the entire use case it could go well beyond what can be posted here as a full answer.

SuiteCrm Rest API: JSON Body attributes throws error when calling POST or PUT

I'm using postman in order to call SuiteCRM REST API.
I tried to call this endpoint
PATCH http://{{suitecrm-url}}/Api/V8/module
and i've added this payload to the body (Content-Type: Application/Json):
{
"data": {
"type": "Accounts",
"id": "3a3ae651-d509-2508-7dc4-5be2e51cc96b",
"attributes": {
"name": "name with space"
}
}
}
When the request is executed SuiteCRM gives this response:
{
"errors": {
"status": 400,
"title": null,
"detail": "The option \"attributes\" with value array is invalid."
}
}
I found out that the problem was the whitespace in the value: when i tried to use the value "namewithspace", it worked.
Anyone has any idea how to solve this problem ?
Thanks in advance
I found out this issue on github that resolved my problem:
https://github.com/salesagility/SuiteCRM/issues/6452
In short to make it work i had to modify the file in
/Api/V8/Params/Options/Fields.php
and replace this line
const REGEX_FIELD_PATTERN = '/[^\w-,]/';
with
const REGEX_FIELD_PATTERN = '/[^\w-,\s\]/';
The person mentioned in github:
this is just for temporary fix and not upgrade safe

Firebase security rule does not prevent removeValue()

I have set the security rule the following, but the .removeValue() is still able to delete records. What am I doing wrong?
{
"rules": {
".read": "auth != null",
".write": "auth != null && newData.exists()"
}
}
Here is the code (in swift) that attempts to remove an entry and according to the security rules should fail, but it succeeds:
let ref = FIRDatabase.database().reference(withPath: "myDatabase/customerIDs")
ref.child("\(customerID)").child(scheduleIDs[indexPath.row]).removeValue()
Your code removes a single value from /myDatabase/customerIDs/$customerId/$scheduleId. Your rules only reject writes that delete the entire database, not writes that delete a single schedule ID. If you want to disallow those, add a rule on the correct path too.
Something like:
{
"rules": {
"myDatabase": {
"customerIDs": {
"$customerId": {
"$scheduleId": {
".validate": "newData.exists()"
}
}
}
}
}
}

Firebase Database REST get with orderBy value and parameters

database.rules.json
{
"rules": {
"meetings" : {
".read": true,
".write": true,
".indexOn" : ["date"]
}
}
}
Request URL
"https://{baseURL}/meetings.json?orderBy=date&equalTo=20181005"
Error Message
error: "orderBy must be a valid JSON encoded path"
But
"https://{baseURL}/meetings.json"
No Error.
What did I do wrong? Plz help me.
The value of the name parameter in your URL needs to be enclosed in " quotes. So:
https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005
Depending on the way you store the values of the date property, the value of the equalTo parameter may also need be enclosed in " quotes. If you store date as a string, it needs to be:
https://{baseURL}/meetings.json?orderBy="date"&equalTo="20181005"
For more on this, read the Firebase documentation on querying using the REST API.
I have faced the exact issue.. and the trick is..the passing value should be "string " encode,
as example below..
searchRecordById(recordId: string) {
return this.http.get(
`https://your-app.firebaseio.com/skdocs.json`,
{
params: {
**orderBy: '"folder"',
equalTo: '"Panchla-2"',**
},
}
);
}
You'll need to escape the quotes for it to work. E.g.
"https://{baseURL}/meetings.json?orderBy=\"date\"&equalTo=\"20181005\""
If you are using curl then try this:
curl 'https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005'
If you fetch url from web or etc then url should be :
https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005