Adejoke
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Doing authorization the wrong way: Common authz anti-patterns to avoid ## Introduction Authorization is an important process in building secure applications. It is the process of determining which users can gain access and what actions they can perform within an application. That's where understanding common anti-patterns comes in. There are pitfalls you want to avoid when building a secure application. By recognizing and avoiding them, you can build an authorization system that stands strong against unauthorized access. In this article, we'll look at authorization, highlighting the anti-patterns to watch out for and the best practices to keep your application secure. For a deeper understanding of authorization and its foundational concepts, check out Cerbos's detailed article on the subject [What is Authorization?](https://www.cerbos.dev/blog/what-is-authorization) ## Implications of poor authorization When authorization isn't done right, a system can have far-reaching consequences like data breaches and loss of customer trust affecting not only the security of your application but also your reputation and bottom line. ### Poorly secured applications Imagine a small e-commerce company that recently launched its new online platform. They’re excited about the potential growth and the ability to serve customers 24/7. However, in the rush to go live, the team overlooked the important part of implementing a secure authorization flow. This then leads to a malicious attacker discovering a loophole in the system and somehow gaining unauthorized access to the admin panel, a section meant only for a handful of trusted employees. With this access, the attacker retrieves sensitive customer data, including addresses and payment details. The company soon faces a massive data breach. This scenario illustrates the risks of poorly secured applications. Without solid authorization set in place, your application becomes a target for unauthorized access, leading to data breaches and system disruptions. It’s a strong warning that securing your application is not optional. ### Lack of trust Customers that once trusted the ecommerce platform with their personal and payment information will begin to feel exposed and vulnerable. They'll start questioning the company's ability to protect their data, resulting in a flood of negative reviews and social media backlash. Trust, once built through positive shopping experiences, will now be replaced with doubt and fear. Restoring customer trust will become an uphill battle, requiring extensive investment in cybersecurity measures, transparent communication and so much time to rebuild trust for the business. ### Financial implications The risks involved in poor authorization are too much to be taken for granted. The financial cost can be very hefty. The legal landscape for data protection is strict, with regulations such as the General Data Protection Regulation (GDPR) imposing heavy fines for non-compliance. The breach the ecommerce store has faced can expose the company to legal scrutiny, and soon, they will be dealing with lawsuits and regulatory investigations. The penalties imposed can be very severe and draining of the companies financials. ## Common authorization anti-patterns Even with the best intentions, authorization systems can sometimes fall prey to common mistakes that leave applications vulnerable. These anti-patterns not only compromise security but also create maintenance challenges. Below, we’ll discuss some of the most prevalent authorization anti-patterns that developers should avoid: * Over-privileged permissions * Hardcoding access control logic * Inconsistent authorization logic * Role explosion Each of these anti-patterns can weaken your application’s security framework. Let’s get into them in detail to understand their implications and how to avoid them. ### Over-permissions When a user is granted more permissions than required,it increases the chances of them misusing these permissions,be it accidental or malicious. For example, a gamestore website where a customer support personnel can delete user accounts instead of just viewing or modifying customer details, this is an over-privileged permission and shouldn't happen. ``` const permissions = ['view', 'edit', 'delete']; // Too much access! Don't do this! if (user.role === 'support') { performAction(permissions); } ``` Instead, lowercase 'a'dopt the principle of least privilege. This principle ensures users only have access to the resources and actions necessary for their roles, minimizing the risk of accidental or malicious misuse. ``` const permissions = ['view', 'edit']; // Restrict to essentials if (user.role === 'support') { performAction(permissions); } ``` ### Hardcoding access control logic Never hardcode authorization rules directly into your application. Such logic is difficult to maintain and requires manual updates, increasing the chance of introducing bugs. ``` if (user.role === 'admin') { // Grant access } else { // Deny access } ``` Instead, use centralized access control systems or frameworks like OAuth, or RBAC that separates business logic from authorization logic. For example, using a centralized RBAC service allows you to modify permissions in one place without changing code across the app. Cerbos has covered more on RBAC with the topic [RBAC in Javascript](https://www.cerbos.dev/blog/role-based-access-control-in-javascript ) you should check it out. ### Inconsistent authorization logic Not following a consistent authorization method all through your apps can lead to exploitable gaps. For example, an API endpoint (`/getUserDetails`) might require a `user` role, while the front-end assumes it is restricted to an admin role. Attackers can bypass the front-end and directly exploit the API. To ensure consistency, implement middleware or centralized authorization policies shared across all layers. ### Role explosion Overloading RBAC with too many small, similar roles can create unmanageable systems. For example, with the game store website, they create a separate role for each store worker instead of grouping permissions. This can lead to anincrease in complexity and make it difficult to manage. You should always use hierarchical roles. Hierarchical roles allow you to define broader categories like 'Manager' or 'Staff' and grant permissions based on these categories, rather than creating individual roles for each worker. You can also combine RBAC with ABAC to handle complex permission requirements without excessive roles. ## Best practices for proper authorization ### Use access control tools Always use tools and frameworks that are easy to maintain and scale for your authorization. A good example will be the use of Cerbos you can define, manage, and update fine-grained access control policies without touching your core application code. ### Monitor for authorization weaknesses Continuously review and monitor your systems for potential authorization weaknesses by regularly conducting penetration tests to identify and patch weak authorization points. For example, you can consider using tools like OWASP ZAP or Burp Suite for regular penetration testing. ### Limiting permissions: Zero-trust Adopt a zero-trust model where no user or system is trusted by default. The zero-trust model operates under the principle of 'never trust, always verify,' requiring strict access verification for every action. Always verify permissions before granting access. For example, you can require re-authentication for sensitive actions like fund transfers or admin-level changes ### Conclusion Authorization is more than a best practice, it's the cornerstone of application security. By avoiding common anti-patterns and taking steps like using access control tools, monitoring weaknesses, and adopting a Zero-Trust Model, you can build secure and trustworthy applications. Secure your applications right, because doing authorization wrong is not an option.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully