Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
233ac24
* test commit
zawlin Feb 28, 2018
c706fd5
* finished register and authenticate api
zawlin Mar 1, 2018
127edf1
* update token
zawlin Mar 1, 2018
52638b9
* add ip info into token
zawlin Mar 1, 2018
e1b7085
* add token checker
zawlin Mar 1, 2018
8c4776b
Add files via upload
Dawnzju Mar 2, 2018
ab42b1b
init docker-compose
xeia Mar 2, 2018
7b89ab0
fix serving of html
xeia Mar 2, 2018
b278bf2
revert changes to original files
xeia Mar 2, 2018
440c206
Merge remote-tracking branch 'origin/add-docker-compose'
zawlin Mar 2, 2018
844efb9
* update docker config and integrate with app
zawlin Mar 2, 2018
6529be0
reformatting
xeia Mar 3, 2018
e4e0f7f
add token expire endpoint
xeia Mar 3, 2018
679e240
* back end api updates
Dawnzju Mar 3, 2018
70f2cab
Merge branch 'master' of https://github.com/CS5331-GROUP-7/rest-api-d…
Dawnzju Mar 3, 2018
43756e0
update endpoint list, reformat code
xeia Mar 3, 2018
306feeb
js added
Dawnzju Mar 3, 2018
223593e
Merge branch 'master' of https://github.com/CS5331-GROUP-7/rest-api-d…
Dawnzju Mar 3, 2018
79513d3
update status codes
xeia Mar 3, 2018
6509199
Merge branch 'master' of github.com:CS5331-GROUP-7/rest-api-development
xeia Mar 3, 2018
e8029af
pages with function without style
shiqing09 Mar 3, 2018
0506ae8
pages with function without style
shiqing09 Mar 3, 2018
3aaed8f
add test structure
xeia Mar 3, 2018
90b1996
add comments
xeia Mar 3, 2018
593cc8b
add meta endpoint tests
xeia Mar 3, 2018
67cac87
add some tests for users endpoint
xeia Mar 3, 2018
9bfc0b9
add more tests for users endpoints
xeia Mar 3, 2018
b532919
add diary empty tests
xeia Mar 4, 2018
1767893
add more tests, fix test errors
xeia Mar 4, 2018
0651f3e
Update UI, update backend receive json
shiqing09 Mar 4, 2018
286e61b
resolve conflicts
shiqing09 Mar 4, 2018
d2d1170
update test
shiqing09 Mar 4, 2018
b0c2c6a
update styles
shiqing09 Mar 5, 2018
61ab88b
Merge branch 'master' of https://github.com/CS5331-GROUP-7/rest-api-d…
shiqing09 Mar 5, 2018
d6cef40
* put debugger
zawlin Mar 3, 2018
3f4af43
Merge remote-tracking branch 'origin/add-test-runner'
zawlin Mar 5, 2018
d09b3a7
Add files via upload
Dawnzju Mar 5, 2018
e2dae2d
* fix some tests[WIP]
zawlin Mar 5, 2018
9361fec
use blueprints
xeia Mar 5, 2018
b705772
* temp fix for test fixture issues
zawlin Mar 5, 2018
166f4fd
update views.py
xeia Mar 5, 2018
a195e00
Merge branch 'master' of github.com:CS5331-GROUP-7/rest-api-development
xeia Mar 5, 2018
b70e697
fix circular imports
xeia Mar 5, 2018
84930e2
add models.py
xeia Mar 5, 2018
99df65a
* change test viws
zawlin Mar 5, 2018
65d4dd5
add helper method
xeia Mar 5, 2018
7606c7f
* unify send_post_data
zawlin Mar 5, 2018
cc46f59
* add util
zawlin Mar 5, 2018
aa57ed4
* fix view problems
zawlin Mar 5, 2018
863fb62
remove counter and userid
Dawnzju Mar 5, 2018
c1cdbde
Merge branch 'master' of https://github.com/CS5331-GROUP-7/rest-api-d…
Dawnzju Mar 5, 2018
6266eee
* fix test's app db configuration
zawlin Mar 5, 2018
79b39ea
fix users tests
xeia Mar 5, 2018
66c2fd9
Merge branch 'master' of github.com:CS5331-GROUP-7/rest-api-development
xeia Mar 5, 2018
a42db21
* fix objectid
zawlin Mar 5, 2018
afbabe2
* fix most test cases
zawlin Mar 5, 2018
e827dfd
update README
xeia Mar 5, 2018
1614c7f
qqq
Dawnzju Mar 5, 2018
e52e536
Merge branch 'master' of https://github.com/CS5331-GROUP-7/rest-api-d…
Dawnzju Mar 5, 2018
75e96a2
update run script
xeia Mar 5, 2018
9572ca7
Merge branch 'master' of github.com:CS5331-GROUP-7/rest-api-development
xeia Mar 5, 2018
6a3272e
Add files via upload
Dawnzju Mar 5, 2018
b97ccf3
Merge branch 'master' of github.com:CS5331-GROUP-7/rest-api-development
xeia Mar 5, 2018
52f54ae
* merged
zawlin Mar 5, 2018
8502ac2
* fix db cleanup
zawlin Mar 5, 2018
399c8fa
test
Dawnzju Mar 5, 2018
e71e8ae
Merge branch 'master' of https://github.com/CS5331-GROUP-7/rest-api-d…
Dawnzju Mar 5, 2018
a12b3ae
* fix some test cases
zawlin Mar 5, 2018
6ccf697
Merge branch 'master' of https://github.com/CS5331-GROUP-7/rest-api-d…
Dawnzju Mar 5, 2018
2caf33d
aaa
Dawnzju Mar 5, 2018
99aa063
* update readme
zawlin Mar 5, 2018
e8e2f50
Merge branch 'master' of github.com:CS5331-GROUP-7/rest-api-development
zawlin Mar 5, 2018
8da2e50
* fix all tests
zawlin Mar 5, 2018
43c74e7
* all done?
zawlin Mar 5, 2018
7135269
* all done?
zawlin Mar 5, 2018
9f00003
* all done?
zawlin Mar 5, 2018
5bde24e
* done
zawlin Mar 5, 2018
4d42149
add flask_app.py
zawlin May 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
.ipynb_checkpoints
.idea
20 changes: 20 additions & 0 deletions Dockerfiles/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:latest

RUN sed -i 's/archive\.ubuntu\.com/ap-southeast-1\.ec2\.archive\.ubuntu\.com/g' /etc/apt/sources.list &&\
apt update
ADD setup.sh requirements.txt /
RUN ls
RUN sh setup.sh
#RUN apt-get install -y python-pip
#RUN pip install -U pip
#RUN pip install -U flask
#RUN pip install -U flask-cors
#RUN pip install -U pymongo
#RUN pip install -U flask-sqlalchemy
#RUN pip install -U flask-mongoengine

WORKDIR /usr/src/app

EXPOSE 8080
# figure out how to change this based on ENV
CMD ["python", "./service/app.py"]
13 changes: 13 additions & 0 deletions Dockerfiles/app/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:latest

RUN sed -i 's/archive\.ubuntu\.com/ap-southeast-1\.ec2\.archive\.ubuntu\.com/g' /etc/apt/sources.list &&\
apt update
ADD setup.sh requirements.txt /
RUN sh setup.sh
RUN rm setup.sh requirements.txt

WORKDIR /usr/src/app

EXPOSE 8080
# figure out how to change this based on ENV
CMD ["sh", "-c", "FLASK_DEBUG=1 FLASK_APP=/usr/src/app/service/flask_app.py python -m flask run -p 8080 -h 0.0.0.0"]
9 changes: 9 additions & 0 deletions Dockerfiles/app/Testfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:2.7

ADD requirements.txt /

RUN pip install -r requirements.txt --user
RUN pip install pytest pytest-cov pytest-flask

COPY . /usr/src/app
WORKDIR /usr/src/app
11 changes: 11 additions & 0 deletions Dockerfiles/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:latest

RUN apt-get update \
&& apt-get install -y apache2

RUN echo "ServerName localhost " >> /etc/apache2/apache2.conf
RUN echo "$user hard nproc 20" >> /etc/security/limits.conf

WORKDIR /var/www/html
EXPOSE 80
CMD rm -f /var/run/apache2/apache2.pid && apachectl -D FOREGROUND
59 changes: 41 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,48 +96,71 @@ Please fill out this section with details relevant to your team.

### Team Members

1. Member 1 Name
2. Member 2 Name
3. Member 3 Name
4. Member 4 Name
1. Chen Hui
2. Kyaw Zawlin
3. Shi Qing
4. Tan Xue Si

### Short Answer Questions

#### Question 1: Briefly describe the web technology stack used in your implementation.

Answer: Please replace this sentence with your answer.
Answer:
1. HTML, JS, CSS for front-end
2. Apache to host web server
3. MongoDB for database,mongoengine as our orm framework
4. Python + Flask for backend API
5. pyTest for testing framework

All contained within their individual docker containers.

#### Question 2: Are there any security considerations your team thought about?

Answer: Please replace this sentence with your answer.
Answer:
1. Since we use http instead of https, password is transmitted in plaintext. The password is hashed and salted before storing into the database.
2. Salting prevent rainbow table type attacks from succeeding and recovering the original plaintext even when our database is compromised.
3. There may be multiple users with the same password, thus the password is salted with both the user's username and password before hash3ng to ensure that the hashed password is not the same for users with the same password.I
4. For user authentication, token is used and this method is not safe since a hacker may be able to get his hands on one token and use it to authenticate as a legitimate user. We include a check for the user's IP address during token authentication to make sure that this is the user who owns the token.
5. In the diary delete and permission adjust API, only diary id and token are given. An attacker may want to delete a diary which does not belong to them. We check the token owner and diary owner before processing the diary. An alternative method such as openid where token is encrypted and can contain private data fields, our method is slightly better because we do not have protection of https.
6. Our app is not vulnerable to typical sql injection attacks as 1) we don't use sql or directly execute db queries and 2) we use an orm framework as our database interface which provides both security and ease of use.

#### Question 3: Are there any improvements you would make to the API specification to improve the security of the web application?

Answer: Please replace this sentence with your answer.
Answer:
1. Hashg the passwrod on the client side and we send the hashed password. The server side can hash again with the salt and store the double hashed result in the db. This weay we can avoid plain text transmission of passwords.
2. For diary delete and permission adjust, processing a group of diaries by given ids rather than one id would be a good idea
3. Better response codes for different responses instead of just returning 200 with json error fields

#### Question 4: Are there any additional features you would like to highlight?

Answer: Please replace this sentence with your answer.
Answer:
1. In order to develop this app in the future, we added a debug mode which can test the APIs and show the status of the database. It is very convenient.
2. We also have a full test suite utilzing standard scalable testing framework pytest.

#### Question 5: Is your web application vulnerable? If yes, how and why? If not, what measures did you take to secure it?

Answer: Please replace this sentence with your answer.
Answer:
1. Yes. Data (password, token, text...) is not encrypted during the transmission. Hacker can obtain it via man in the middle attack. We can secure it via https protocol. However,since api require us to provide http. We can implement this by proxying flask traffic through apache server.
2. There is no limitation for response times. This app is vulnerable under flooding attack.

#### Feedback: Is there any other feedback you would like to give?

Answer: Please replace this sentence with your answer.
Answer: Docker is fun!

### Declaration

#### Please declare your individual contributions to the assignment:

1. Member 1 Name
- Integrated feature x into component y
- Implemented z
2. Member 2 Name
1. Chen Hui
- Implemented diary and user API endpoints
- Implemented additional test cases
2. Kyaw Zawlin
- Designed database schema
- Setup app and database interfaces
3. Shi Qing
- Front-end design
- Wrote the front-end code
3. Member 3 Name
- Designed the database schema
4. Member 4 Name
- Implemented x
4. Tan Xue Si
- Implemented test runner
- Dockerize and docker-compose containers

4 changes: 4 additions & 0 deletions clean_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#/bin/sh

sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)
4 changes: 4 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -e
sudo docker-compose -f docker-compose-dev.yml build
sudo docker-compose -f docker-compose-dev.yml up
25 changes: 25 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '2'
services:
app:
build:
context: ./
dockerfile: Dockerfiles/app/Dockerfile-dev
ports:
- "8080:8080"
depends_on:
- mongodb
volumes:
- ./src:/usr/src/app

web:
image: apache
build: Dockerfiles/web
ports:
- "80:80"
volumes:
- ./src/html:/var/www/html

mongodb:
image: mongo:latest
volumes:
- /data
28 changes: 28 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '2'
services:
tests:
build:
context: ./
dockerfile: Dockerfiles/app/Testfile
links:
- mongodb
- app

app:
build:
context: ./
dockerfile: Dockerfiles/app/Dockerfile-dev
ports:
- "8080:8080"
depends_on:
- mongodb
volumes:
- ./src:/usr/src/app

mongodb:
image: mongo:latest

ports:
- "27017:27017"
volumes:
- /data
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '2'
services:
app:
build: Dockerfiles/app
ports:
- "8080:8080"
depends_on:
- mongodb
volumes:
- ./src:/usr/src/app

web:
image: apache
build: Dockerfiles/web
ports:
- "80:80"
volumes:
- ./src/html:/var/www/html

mongodb:
build: Dockerfiles/mongodb
volumes:
- /data
6 changes: 6 additions & 0 deletions drop_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

from flask_mongoengine import MongoEngine
from mongoengine import connect
db = connect('db_test',host='mongodb')
db.drop_database('db_test')
db.close()
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flask
pymongo
flask-sqlalchemy
flask-cors
flask-mongoengine
6 changes: 4 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ fi
TEAMID=`md5sum README.md | cut -d' ' -f 1`
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker build . -t $TEAMID
docker run -p 80:80 -p 8080:8080 -t $TEAMID
#docker build . -t $TEAMID
#docker run -p 80:80 -p 8080:8080 -t $TEAMID
docker-compose -f docker-compose-dev.yml -p $TEAMID build
docker-compose -f docker-compose-dev.yml -p $TEAMID up
5 changes: 5 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e
apt install python-pip -y
pip install --upgrade pip
pip install -r requirements.txt --user
Empty file added src/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions src/html/diary/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Create Diary</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="col-sm-12"><h1>Create Diary</h1></div>

<form class="container" name="diaryForm" onsubmit="return createDiary()">
<div class="form-group row">
<label class="col-sm-2 col-form-label">Title: </label>
<div class="col-sm-10"><input class="form-control" type="text" name="title" required/></div>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Text: </label>
<div class="col-sm-10"><textarea class="form-control" name="text" required></textarea></div>
</div>

<div class="form-group row">
<label class="col-sm-2 col-form-label">Public: </label>
<div class="col-sm-10">
<input type="radio" name="public" value="true">True<br>
<input type="radio" name="public" value="false" checked>False
</div>
</div>

<div class="form-group row">
<input class="btn btn-primary offset-sm-2 col-sm-4" type="submit" value="Submit">
</div>
</form>
<div id="response_status">
</div>
<div id="demo_dbg">
</div>
<script src="./create.js"></script>
</body>
</html>
52 changes: 52 additions & 0 deletions src/html/diary/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var API_ENDPOINT = "http://localhost:8080"

function ajax_post(url, data, callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 201) {
console.log('responseText:' + xmlhttp.responseText);
try {
var data = JSON.parse(xmlhttp.responseText);
} catch(err) {

document.getElementById("demo_dbg").innerHTML = err.message + " in " + xmlhttp.responseText;
console.log(err.message + " in " + xmlhttp.responseText);
return ;
}
callback(data);
}else{

document.getElementById("demo_dbg").innerHTML = xmlhttp.responseText;
}
};

xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.send(JSON.stringify(data));
}

function createDiary() {
var title = document.forms["diaryForm"]["title"].value;
var text = document.forms["diaryForm"]["text"].value;
var public = document.forms["diaryForm"]["public"].value;
var token = localStorage.getItem("token");

var data = {
'title': title,
'text': text,
'token': token,
'public': (public === "true")? true: false
}

ajax_post(API_ENDPOINT + '/diary/create', data, function(data) {
if (data.status) {
document.getElementById("response_status").innerHTML = "Create diary success";
}
else {
document.getElementById("response_status").innerHTML = "Create diary failed";
}
});
return false;
}


19 changes: 19 additions & 0 deletions src/html/diary/private-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>My Diary List</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="col-sm-12"><h1>My Private Diary List</h1></div>

<div id="my-diary-list" class="container">
</div>
<div id="response_status">
</div>
<div id="demo_dbg">
</div>
<script src="./private-list.js"></script>
</body>
</html>
Loading