Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS5331 Submission #19

Open
wants to merge 100 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
56b842b
Add names of team members to readme
weechen Feb 19, 2018
66b3c49
Merge pull request #1 from MXs-Org/update-readme
weechen Feb 19, 2018
d836518
Update files to start DB container and link app to it
weechen Feb 26, 2018
b27342a
Add sleep, wait for db to finish loading
weechen Feb 26, 2018
473678a
Allow persistent storage for db
weechen Feb 27, 2018
2bc94d1
Update README.md
weechen Feb 27, 2018
1054a53
Merge pull request #2 from MXs-Org/start-docker-db
weechen Feb 27, 2018
f5d47f4
Update run.sh
mxchai Feb 28, 2018
85a0951
Update comments, replace python packages
mxchai Feb 28, 2018
c58e437
Update app, add database and models
mxchai Feb 28, 2018
9eb639f
add entry and token model and their relationships with user
garbanzos Feb 28, 2018
9bd0e62
added diary routes skeleton code
garbanzos Feb 28, 2018
97c6226
Update User model for password hashing
mxchai Feb 28, 2018
d4f425b
Add /users/register route
mxchai Feb 28, 2018
883da1a
added base ui html that is the parent of all htmls
garbanzos Feb 28, 2018
5d2de5f
Merge branch 'origin/diary-api' into users
mxchai Mar 1, 2018
512b973
Merge pull request #4 from MXs-Org/base-ui
mxchai Mar 1, 2018
55d1c02
Update User model
mxchai Mar 1, 2018
645e69e
Add /users/authenticate
mxchai Mar 1, 2018
08d8393
Fix error in User model
mxchai Mar 1, 2018
a54fa47
Add /users/expire
mxchai Mar 1, 2018
2f14c5d
Add /users
mxchai Mar 1, 2018
2d3076d
Fix minor route errors
mxchai Mar 1, 2018
9b1f54d
Update run.sh to remove MySQL-related commands
mxchai Mar 1, 2018
630dbad
Update team members
mxchai Mar 1, 2018
eb7e89f
Merge pull request #3 from MXs-Org/users
mxchai Mar 1, 2018
9f9cbda
Update ENDPOINT_LIST
mxchai Mar 1, 2018
e58645c
Rewrite to handle application/json instead of form-data
mxchai Mar 1, 2018
d732073
Update Entry model to change 'publish_date', add method to dump JSON
mxchai Mar 2, 2018
267cc58
Add /diary and /diary/create
mxchai Mar 2, 2018
524e41d
Merge pull request #5 from MXs-Org/diary
mxchai Mar 2, 2018
7a21116
Clean and update README
mxchai Mar 2, 2018
1360b67
Merge branch 'master' of https://github.com/MXs-Org/rest-api-development
mxchai Mar 2, 2018
48f7545
Clean up
mxchai Mar 2, 2018
6ebe201
add delete and change_permissions api for diary
garbanzos Mar 2, 2018
d38f19b
moved templates into some dir as app.py so that they can be rendered …
garbanzos Mar 2, 2018
37ab7b0
added create post ui and base form ui
garbanzos Mar 2, 2018
9340bb6
added skeleton login and register form template
garbanzos Mar 2, 2018
c339bfc
add static folder to hold css, js and img
garbanzos Mar 2, 2018
3c01552
add login and register form ui
garbanzos Mar 2, 2018
c4a2266
attempt to link api to register ui
garbanzos Mar 2, 2018
b06ca42
change register_form ajax contenttype to json and added toasts
garbanzos Mar 2, 2018
626f8f7
change auth api to match specs and added login_form submit handler
garbanzos Mar 2, 2018
6d84824
Merge remote-tracking branch 'origin/shift_ui_port_80' into diary-api-ui
garbanzos Mar 2, 2018
83e43d3
Move views to port 80
weechen Mar 2, 2018
81d924f
WIP
mxchai Mar 3, 2018
6cecdd5
Update auth.js skeleton
mxchai Mar 3, 2018
68835c6
Merge branch 'port_80_extra' into diary-api-ui
mxchai Mar 3, 2018
e6e8320
login now stores token in localstorage and minor refactoring
garbanzos Mar 3, 2018
48fdd6f
added logout js and add links to the navbar
garbanzos Mar 3, 2018
addc03c
Add route for token validation. Not part of testing API
mxchai Mar 3, 2018
41de448
Modify navbar to display different options according to auth status
mxchai Mar 3, 2018
edaa974
/diary now shows all public shows of users
garbanzos Mar 3, 2018
30eb6ab
Remove extra if-else block and debug messages
weechen Mar 3, 2018
e851b6e
Merge pull request #12 from MXs-Org/fix-navbar
weechen Mar 3, 2018
c507bde
added my_entries view
garbanzos Mar 3, 2018
b8e677f
Merge branch 'diary-api-ui' of github.com:MXs-Org/rest-api-developmen…
garbanzos Mar 3, 2018
b82c8a9
Make all external JS local
mxchai Mar 3, 2018
438e44a
Fix login failure materialize toast
mxchai Mar 3, 2018
a684bc9
Resolve merge conflicts, remove auth.js in views and add create_entry
weechen Mar 3, 2018
9431025
Remove endpoints
weechen Mar 3, 2018
4cc1962
Fix create entry bugs
weechen Mar 3, 2018
cd3ec26
Add missing fonts
weechen Mar 3, 2018
235861b
Merge pull request #16 from MXs-Org/Add-fonts
weechen Mar 3, 2018
1ec45e8
Merge remote-tracking branch 'origin/diary-api-ui' into create-form
weechen Mar 3, 2018
919de2e
Prepare js methods and views
weechen Mar 3, 2018
ef3cf70
Implement delete post
weechen Mar 4, 2018
cbe5648
Merge pull request #17 from MXs-Org/delete-diary-ui
weechen Mar 4, 2018
8f4da03
Fix bug in delete and implement change in visibility
weechen Mar 4, 2018
6af84e6
Merge pull request #18 from MXs-Org/diary-change-permission-ui
weechen Mar 4, 2018
ed34700
Save sqlite db into host system
weechen Mar 4, 2018
813ac4e
Merge pull request #20 from MXs-Org/persist-database
weechen Mar 4, 2018
c5f83e8
Fix login/logout and my posts link
weechen Mar 4, 2018
6b806aa
Move navbar out of auth.js
weechen Mar 4, 2018
30e60fc
add user check endpoint
weechen Mar 4, 2018
f7666ca
Move auth helpers out
weechen Mar 4, 2018
f8a2677
Clean up auth.js calls
weechen Mar 4, 2018
d6c3edd
Add in redirect.js
weechen Mar 4, 2018
1ee6e02
Fix login form bug
weechen Mar 4, 2018
24c2dca
Merge pull request #21 from MXs-Org/fix-navbar
weechen Mar 4, 2018
93d6895
remove debugging api and delete and change permissions api now checks…
garbanzos Mar 5, 2018
c546282
removed all users from navbar
garbanzos Mar 5, 2018
800566c
Default message when no public entries
weechen Mar 5, 2018
4cab2ad
Add default message for my entries page
weechen Mar 5, 2018
b2a6f83
Merge pull request #22 from MXs-Org/touch-up-ui
weechen Mar 5, 2018
3910c90
center login page
garbanzos Mar 5, 2018
2bd7ac6
Merge branch 'diary-api-ui' of github.com:MXs-Org/rest-api-developmen…
garbanzos Mar 5, 2018
a47c376
Reject empty title or entry posts and touch up ui
weechen Mar 5, 2018
6d98d23
Merge pull request #23 from MXs-Org/reject-empty-entries
weechen Mar 5, 2018
f6a7e85
Auto stash before merge of "diary-api-ui" and "origin/diary-api-ui"
weechen Mar 5, 2018
82b8837
Merge pull request #24 from MXs-Org/add-screenshot
weechen Mar 5, 2018
340c94b
Merge pull request #6 from MXs-Org/diary-api-ui
garbanzos Mar 5, 2018
c41c3b3
Standardize server responses when unsuccessful request is made
mxchai Mar 5, 2018
602b9e0
Merge branch 'diary-api-ui' of https://github.com/MXs-Org/rest-api-de…
mxchai Mar 5, 2018
a86260e
added screenshots
garbanzos Mar 5, 2018
24941a7
Remove internal route from ENDPOINT_LIST
mxchai Mar 5, 2018
8756854
Merge pull request #25 from MXs-Org/diary-api-ui
mxchai Mar 5, 2018
7cbbf12
Update README
mxchai Mar 5, 2018
74bba62
Update README.md
mxchai Mar 5, 2018
525be46
Update README.md
mxchai Mar 5, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv/
*.pyc
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ RUN apt-get install -y apache2
RUN pip install -U pip
RUN pip install -U flask
RUN pip install -U flask-cors
RUN pip install flask-sqlalchemy
ENV FLASK_APP app.py
RUN echo "ServerName localhost " >> /etc/apache2/apache2.conf
RUN echo "$user hard nproc 20" >> /etc/security/limits.conf
ADD ./src/service /service
Expand Down
111 changes: 84 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ sudo docker run hello-world

sudo ./run.sh
```

(Docker CE installation instructions are from this
[link](https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository).)

Expand Down Expand Up @@ -84,60 +83,118 @@ If a response is received, you're good to go.
**Please replace the details below with information relevant to your team.**

## Screenshots

Please replace the example screenshots with screenshots of your completed
project. Feel free to include more than one.

![Sample Screenshot](./img/samplescreenshot.png)
### Login
![Login](./img/login.png)
### Register
![Register](./img/register.png)
### Public entries
![Public entries](./img/publicposts.png)
### Authenticated user's entries with delete and change permissions
![My entries](./img/myposts.png)
### Create entry
![Create](./img/create.png)

## Administration and Evaluation

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. Chai Ming Xuan
2. Tan Yi Yan
3. Tan Wee Chen William

### Short Answer Questions

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

Answer: Please replace this sentence with your answer.
Answer:

On the backend, we used the Flask microframework for the web application, SQLite as the database and Flask-SQLAlchemy as the database ORM.

As for the frontend, we mostly used basic HTML, Python Jinja2 for templating, Materialize CSS for styling, and JavaScript libraries such as jQuery and handlebars.

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

Answer: Please replace this sentence with your answer.
Answer:

**Storing password hashes**
Instead of storing the password of the the user in plaintext, we stored a hash of the password.

**Protection against SQL injection**
Our web application is not vulnerable to SQL injection attacks as we chose to use SQLAlchemy that provides automatic quoting of special characters such as semicolons and apostrophes.

**Protection against XSS**
In addition, our web application is also not vulnerable to Cross Site Scritping (XSS) as we enabled Jinja2 to auto escape all values loaded in our web applications' pages.

**Protection against user enumeration**
When a user submits a wrong username or password when logging in, the server gives a general authentication error message instead of specific messages. This prevents attackers from finding out if they have submitted a non-existent username or a wrong password. They cannot find out if a user exist or not through the login page.

**CSRF**
A side-effect of not using HTTP Cookies for authentication is that the application is not vulnerable to traditional CSRF, since the session token is not automatically sent, unlike a cookie. We do acknowledge that storing the session token in Local Storage does not automatically make it any more secure than cookies, and comes with its own downsides.

#### 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:

There are a few areas that we can improve on, such as
- Password strength
- Expiring the password token
- Salting the password

**Password strength**
There are curently no restrictions on the password length and complexity. A user can use an extremely weak password such as `password1` and still be allowed to register.

**Expiring tokens**
Currently, the server does not expire a token unless it is explictly told to do so via the `/users/expire` API. This may not be ideal as any stolen token will be valid until a `/users/expire` request is sent. To mitigate the damages that can be caused by a stolen token, the server can expire a token automatically after a fixed period of time e.g. after 5 days.

**Salting the password**
Passwords can be salted before they are hashed in order to defend against dictionary attacks.

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

Answer: Please replace this sentence with your answer.
Answer:

**Checking user authentication**
When an unauthenticated user tries to access pages that require authentication, they get redirected back to the login page. Similarly, when an authenticated user tries to access access the login and registration page, they get redirected to the public diary entries page.

#### 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:

Yes. Our web application is vulnerable in the following ways:
- Brute-force attacks
- Spamming user registration
- Unencrypted traffic in HTTP
- Token stored in plaintext

**Brute-force attacks**
Attackers can send as many requests as they want to the server, and the number of requests per unit time is not limited. If they know the username of a user, they can make as many password attempts as they want to the server. This is because we have not implemented a feature to throttle requests to a server.

**Spamming user registration**
Attackers can use bots to spam user registrations and fill our database with fake users. This is because we did not implement any mechanisms to verify whether the user is a human or not, such as CAPTCHA.

**Unencrypted traffic in HTTP**
The web application is served on the HTTP protocol that does not provide confidentiality and integrity. Since all HTTP traffic is unencrypted, a network attacker is able to sniff sensitive data such as passwords and session tokens because all data is sent in the clear. In addition, since there are no integrity checks in HTTP, an attacker can easily modifiy the data sent between the server and the client.

**Token stored in plaintext**
In the event that the database gets compromised, the attacker will have access to all the tokens stored in the database. Having access to the tokens is equivalent to getting the login credentials of a user. Storing the hash of a password becomes pointless. By hashing the tokens, the attacker will not be able to log into any user's account using the hash of their token.

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

Answer: Please replace this sentence with your answer.
Answer:
- It was good to have the freedom of choice for our tech stack.
- It was challenging to use Docker.
- API specification was very clear.

### 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. Chai Ming Xuan
- Implemented the Users and some of the Diary APIs
- Wrote the front-end code
2. Tan Yi Yan
- Implemented some of the Diary API
- Wrote the front-end code
3. Tan Wee Chen William
- Setup the database and designed all its schema
- Wrote the front-end code
3. Member 3 Name
- Designed the database schema
4. Member 4 Name
- Implemented x

Binary file added img/create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/myposts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/publicposts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/register.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/samplescreenshot.png
Binary file not shown.
13 changes: 9 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#!/bin/bash

if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
then echo "Please run as root"
exit
fi

TEAMID=`md5sum README.md | cut -d' ' -f 1`
cp -R -u -p test.db /tmp/test.db

# Tears down any running containers
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)

# Builds web application image and runs webapp container
TEAMID=`md5sum README.md | cut -d' ' -f 1`
docker build . -t $TEAMID
docker run -p 80:80 -p 8080:8080 -t $TEAMID
docker run -v /tmp/test.db:/tmp/test.db -p 80:80 -p 8080:8080 -t $TEAMID
Loading