I am working on an Angular 5 web application which is about taking online exams and instantly telling the result. After attempting the test, the client side will request to the server for the list of correct answers and then it will compare user's answers with the right answers received from firebase server, this is why I am bound (I guess so) to store API at client side.
My question is, after deploying the app (uglifying, tree-shaking) will it be possible for anyone (even authenticated users) to access APIs which are hard-coded in my web app? If yes, then how easy it will be for them?
In the end, if it is not a good practice to store an API key in the app. What can I do to secure firebase APIs used in my app.
I don't have any hosting server, my app will completely rely on firebase.
Note: I found some information online, regarding this topic. Most of it was very confusing for me or was about AngularJS/Angular 4.x apps (with personal back-end)/Android Applications.
Update: When the user opts to attempt test, the questions and options stored on the server are fetched using http request:
//Component Code
testData: any;
fetchTest() {
this.obtainTest.getTest()
.subscribe(
(response: Response) => {
this.testData = response.json();
console.log(this.testData);
},
(error) => console.log(error)
)
}
//Code from http Service
getTest(){
console.log('Obtain Test Service is working...');
return this.http.get('https://myfyp-40291.firebaseio.com/tests/-L0f5r_-tHLMk45AU5zg.json')
}
In testData
questions and their possible answers are stored from firebase server and then showed to the user. Then the user selects possible right answers, when he is done. The right answers which are separately stored in another json object at firebase server, are requested using http request and the user's answers are compared with those right answers to show him his score.
getKeys(){
return this.http.get('https://myfyp-40291.firebaseio.com/keys/-L0k_SQivBudFGcNjD-k.json');
}
Now this is the API I want to secure. I have read about firebase rules. For this key write will be surely restricted for the user but if I block read as well then how will he be able to get the right answers in the end? If I let him read then there is a threat he can access api key from the code, download the json object manually and know about all the right answers and attempt test accordingly.
In this situation please advice me what should I do to solve this issue?
//English is not my first language so sorry for mistakes and confusion.