Sunday, November 19, 2017

API Security Checklist


Checklist of the most important security countermeasures when designing, testing, and releasing your API.

Authentication

  •  Don't use Basic Auth Use standard authentication (e.g. JWTOAuth).
  •  Don't reinvent the wheel in Authenticationtoken generationpassword storage. Use the standards.
  •  Use Max Retry and jail features in Login.
  •  Use encryption on all sensitive data.

JWT (JSON Web Token)

  •  Use a random complicated key (JWT Secret) to make brute forcing the token very hard.
  •  Don't extract the algorithm from the payload. Force the algorithm in the backend (HS256 or RS256).
  •  Make token expiration (TTLRTTL) as short as possible.
  •  Don't store sensitive data in the JWT payload, it can be decoded easily.

OAuth

  •  Always validate redirect_uri server-side to allow only whitelisted URLs.
  •  Always try to exchange for code and not tokens (don't allow response_type=token).
  •  Use state parameter with a random hash to prevent CSRF on the OAuth authentication process.
  •  Define the default scope, and validate scope parameters for each application.

Access

  •  Limit requests (Throttling) to avoid DDoS / brute-force attacks.
  •  Use HTTPS on server side to avoid MITM (Man In The Middle Attack).
  •  Use HSTS header with SSL to avoid SSL Strip attack.

Input

  •  Use the proper HTTP method according to the operation: GET (read)POST (create)PUT/PATCH (replace/update), and DELETE (to delete a record), and respond with 405 Method Not Allowed if the requested method isn't appropriate for the requested resource.
  •  Validate content-type on request Accept header (Content Negotiation) to allow only your supported format (e.g. application/xmlapplication/json, etc) and respond with 406 Not Acceptable response if not matched.
  •  Validate content-type of posted data as you accept (e.g. application/x-www-form-urlencodedmultipart/form-dataapplication/json, etc).
  •  Validate User input to avoid common vulnerabilities (e.g. XSSSQL-InjectionRemote Code Execution, etc).
  •  Don't use any sensitive data (credentialsPasswordssecurity tokens, or API keys) in the URL, but use standard Authorization header.
  •  Use an API Gateway service to enable caching, Rate Limit policies (e.g. QuotaSpike ArrestConcurrent Rate Limit) and deploy APIs resources dynamically.

Processing

  •  Check if all the endpoints are protected behind authentication to avoid broken authentication process.
  •  User own resource ID should be avoided. Use /me/orders instead of /user/654321/orders.
  •  Don't auto-increment IDs. Use UUID instead.
  •  If you are parsing XML files, make sure entity parsing is not enabled to avoid XXE (XML external entity attack).
  •  If you are parsing XML files, make sure entity expansion is not enabled to avoid Billion Laughs/XML bomb via exponential entity expansion attack.
  •  Use a CDN for file uploads.
  •  If you are dealing with huge amount of data, use Workers and Queues to process as much as possible in background and return response fast to avoid HTTP Blocking.
  •  Do not forget to turn the DEBUG mode OFF.

Output

  •  Send X-Content-Type-Options: nosniff header.
  •  Send X-Frame-Options: deny header.
  •  Send Content-Security-Policy: default-src 'none' header.
  •  Remove fingerprinting headers - X-Powered-ByServerX-AspNet-Version etc.
  •  Force content-type for your response, if you return application/json then your response content-type is application/json.
  •  Don't return sensitive data like credentialsPasswordssecurity tokens.
  •  Return the proper status code according to the operation completed. (e.g. 200 OK400 Bad Request401 Unauthorized405 Method Not Allowed, etc).

CI & CD

  •  Audit your design and implementation with unit/integration tests coverage.
  •  Use a code review process and disregard self-approval.
  •  Ensure that all components of your services are statically scanned by AV software before push to production, including vendor libraries and other dependencies.
  •  Design a rollback solution for deployments.

Thursday, November 16, 2017

Angular LifeCycle Hook

Lifecycle sequence

After creating a component/directive by calling its constructor, Angular calls the lifecycle hook methods in the following sequence at specific moments:
HookPurpose and Timing
ngOnChanges()
Respond when Angular (re)sets data-bound input properties. The method receives a SimpleChanges object of current and previous property values.
Called before ngOnInit() and whenever one or more data-bound input properties change.
ngOnInit()
Initialize the directive/component after Angular first displays the data-bound properties and sets the directive/component's input properties.
Called once, after the first ngOnChanges().
ngDoCheck()
Detect and act upon changes that Angular can't or won't detect on its own.
Called during every change detection run, immediately after ngOnChanges()and ngOnInit().
ngAfterContentInit()
Respond after Angular projects external content into the component's view.
Called once after the first ngDoCheck().
A component-only hook.
ngAfterContentChecked()
Respond after Angular checks the content projected into the component.
Called after the ngAfterContentInit() and every subsequent ngDoCheck().
A component-only hook.
ngAfterViewInit()
Respond after Angular initializes the component's views and child views.
Called once after the first ngAfterContentChecked().
A component-only hook.
ngAfterViewChecked()
Respond after Angular checks the component's views and child views.
Called after the ngAfterViewInit and every subsequent ngAfterContentChecked().
A component-only hook.
ngOnDestroy
Cleanup just before Angular destroys the directive/component. Unsubscribe Observables and detach event handlers to avoid memory leaks.
Called just before Angular destroys the directive/component.

Tuesday, November 7, 2017

Comprehensive learning path – Data Science in Python

Journey from a Python noob to a Kaggler on Python

So, you want to become a data scientist or may be you are already one and want to expand your tool repository. You have landed at the right place. The aim of this page is to provide a comprehensive learning path to people new to python for data analysis. This path provides a comprehensive overview of steps you need to learn to use Python for data analysis. If you already have some background, or don’t need all the components, feel free to adapt your own paths and let us know how you made changes in the path.
You can also check the mini version of this learning path –> Infographic: Quick Guide to learn Data Science in Python

Step 0: Warming up

Before starting your journey, the first question to answer is:
Why use Python?
or
How would Python be useful?
Watch the first 30 minutes of this talk from Jeremy, Founder of DataRobot at PyCon 2014, Ukraine to get an idea of how useful Python could be.

Step 1: Setting up your machine
Now that you have made up your mind, it is time to set up your machine. The easiest way to proceed is to just download Anaconda from Continuum.io . It comes packaged with most of the things you will need ever. The major downside of taking this route is that you will need to wait for Continuum to update their packages, even when there might be an update available to the underlying libraries. If you are a starter, that should hardly matter.
If you face any challenges in installing, you can find more detailed instructions for various OS here

Step 2: Learn the basics of Python language

You should start by understanding the basics of the language, libraries and data structure. The free interactive Python tutorial by DataCamp is one of the best places to start your journey. This 4 hour coding course focuses on how to get started with Python for data science and by the end you should be comfortable with the basic concepts of the language.
Specifically learn: Lists, Tuples, Dictionaries, List comprehensions, Dictionary comprehensions 
Alternate resources: If interactive coding is not your style of learning, you can also look at The Google Class for Python. It is a 2 day class series and also covers some of the parts discussed later.

Step 3: Learn Regular Expressions in Python

You will need to use them a lot for data cleansing, especially if you are working on text data. The best way to learn Regular expressions is to go through the Google class and keep this cheat sheet handy.
Assignment: Do the baby names exercise
If you still need more practice, follow this tutorial for text cleaning. It will challenge you on various steps involved in data wrangling.

Step 4: Learn Scientific libraries in Python – NumPy, SciPy, Matplotlib and Pandas

This is where fun begins! Here is a brief introduction to various libraries. Let’s start practicing some common operations.
  • Practice the NumPy tutorial thoroughly, especially NumPy arrays. This will form a good foundation for things to come.
  • Next, look at the SciPy tutorials. Go through the introduction and the basics and do the remaining ones basis your needs.
  • If you guessed Matplotlib tutorials next, you are wrong! They are too comprehensive for our need here. Instead look at this ipython notebook till Line 68 (i.e. till animations)
  • Finally, let us look at Pandas. Pandas provide DataFrame functionality (like R) for Python. This is also where you should spend good time practicing. Pandas would become the most effective tool for all mid-size data analysis. Start with a short introduction, 10 minutes to pandas. Then move on to a more detailed tutorial on pandas.
  • Check out DataCamp’s course on Pandas Foundations
Additional Resources:
  • If you need a book on Pandas and NumPy, “Python for Data Analysis by Wes McKinney”
  • There are a lot of tutorials as part of Pandas documentation. You can have a look at them here
Assignment: Solve this assignment from CS109 course from Harvard.

Step 5: Effective Data Visualization

Go through this lecture form CS109. You can ignore the initial 2 minutes, but what follows after that is awesome! Follow this lecture up with this assignment
Check out Bokeh Data Visualization Tutorial from DataCamp

Step 6: Learn Scikit-learn and Machine Learning

Now, we come to the meat of this entire process. Scikit-learn is the most useful library on python for machine learning. Here is a brief overview of the library. Go through lecture 10 to lecture 18 from CS109 course from Harvard. You will go through an overview of machine learning, Supervised learning algorithms like regressions, decision trees, ensemble modeling and non-supervised learning algorithms like clustering. Follow individual lectures with the assignments from those lectures.

Additional Resources:
Assignment: Try out this challenge on Kaggle

Step 7: Practice, practice and Practice

Congratulations, you made it!
You now have all what you need in technical skills. It is a matter of practice and what better place to practice than compete with fellow Data Scientists on Kaggle. Go, dive into one of the live competitions currently running on Kaggle and give all what you have learnt a try!

Step 8: Deep Learning

Now that you have learnt most of machine learning techniques, it is time to give Deep Learning a shot. There is a good chance that you already know what is Deep Learning, but if you still need a brief intro, here it is.
I am myself new to deep learning, so please take these suggestions with a pinch of salt. The most comprehensive resource is deeplearning.net. You will find everything here – lectures, datasets, challenges, tutorials. You can also try the course from Geoff Hinton a try in a bid to understand the basics of Neural Networks.

11 things we Should Never Say At Work

What you say matters. Whether you're voicing an idea during a meeting or making an offhand comment at lunch, everything you say adds to your overall character.
In the new book "Executive Presence: The Missing Link Between Merit and Success," Sylvia Ann Hewlett says three things signal whether a professional is leadership material: how they act, how they look, and how they speak. 
Speaking eloquently not only improves your daily communications, it builds up your overall persona and executive presence. "Every verbal encounter is a vital opportunity to create and nurture a positive impression," Hewlett writes. 
Some phrases instantly undermine your authority and professionalism, and should be banned from the office. Here are 11 things you should never say at work:

1. "Does that make sense?"

Instead of making sure you're understood, asking this tells the listener that you don't fully understand the idea yourself, career coach Tara Sophia Mohr told Refinery 29. Instead, she suggests asking, "What are your thoughts?"

2. "It's not fair." 

Simply complaining about an injustice isn't going to change the situation. "Whether it's a troubling issue at work or a serious problem for the planet, the point in avoiding this phrase is to be proactive about the issues versus complaining, or worse, passively whining," Darlene Price, author of "Well Said! Presentations and Conversations That Get Results" told Forbes

3. "I haven't had time."

"More often than not, this is simply not true," said Atle Skalleberg in a LinkedIn post. Whether you didn't make time for the task or forgot about it, Skalleberg suggests giving a time when it will be done instead of explaining why it's late. 

4. "Just"

Adding "just" as a filler word in sentences, such as saying "I just want to check if..." or "I just think that..." may seem harmless, but it can detract from what you're saying. "We insert justs because we're worried about coming on too strong," says Mohr, "but they make the speaker sound defensive, a little whiny, and tentative." Leave them out, and you'll speak with more authority. 

5. "But I sent it in an email a week ago."

If someone doesn't get back to you, it's your job to follow up, says Skalleberg. Be proactive when communicating instead of letting the other person take the blame.

6. "I hate..." or "It's so annoying when..."

Insults have no place in the office, especially when directed at a specific person or company practice. "Not only does it reveal juvenile school-yard immaturity, it's language that is liable and fire-able," says Price.

7. "That's not my responsibility."

Even if it's not your specific duty, stepping up to help shows that you're a team player and willing to go the extra mile. "At the end of the day, we're all responsible," Skalleberg says.

8. "You should have..."

"Chances are, these fault-finding words inflict feelings of blame and finger-pointing," Price says. She suggests using a positive approach instead, such as saying, "In the future, I recommend..." 

9. "I may be wrong, but..."

Price calls this kind of language "discounting," meaning that it immediately reduces the impact of whatever you're about to say. "Eliminate any prefacing phrase that demeans the importance of who you are or lessens the significance of what you contribute," she says. 

10. "Sorry, but..."

This implies that you're automatically being annoying. "Don't apologize for taking up space, or for having something to say," says Mohr. 

11. "Actually..."

Prefacing sentences with this word, as in, "Actually, it's right over there," or "Actually, you can do it this way," puts distance between you and the listener by hinting that they were somehow wrong, according to Carolyn Kopprasch, chief happiness officer at Buffer. Rephrase to create a more positive sentiment.