FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Javascript/Python: Tokens built from predictable UUIDs by bananabr · Pull Request #10943 · github/codeql · GitHub

/ codeql Public

Javascript/Python: Tokens built from predictable UUIDs - #10943

Merged
tausbn merged 12 commits into
github:mainfrom
bananabr:main
Oct 27, 2022
Merged

tausbn merged 12 commits into
github:mainfrom
bananabr:main

Conversation

Copy link
Copy Markdown
Contributor

A couple of queries based on Daniel Thatcher's work https://www.intruder.io/research/in-guid-we-trust to look for "tokens" and "codes" generated from predictable UUIDs.

github-actions Bot commented Oct 24, 2022
edited
Loading

Copy link
Copy Markdown
Contributor

QHelp previews:

javascript/ql/src/experimental/Security/CWE-340/TokenBuiltFromUUID.qhelp

Predictable token

GUIDs (often called UUIDs) are widely used in modern web applications. One common use for UUIDs is the generation of one-time-use tokens. These can used for password reset, and e-mail confirmation routines, for example.

There are five versions of UUIDs defined in RFC 4122. Out of the five, four are generated in a predictable manner. This means it is possible for someone to predict future UUIDs based on a sample generated by the target application.

Version four is the only UUID version expected to be randomly generated. Therefore, for situations where predictable tokens are not desired (e.g. password reset tokens), all other versions should be avoided.

Recommendation

When using GUIDs/UUIDs for generating tokens that should not be predictable, use version four.

Example

This example shows a UUID v1 being used for a password reset routine.

var uuid = require('uuid');

module.exports = function (app) {

    app.use('/login', function (req, res) {

        var username = req.body.username;
        var password = req.body.password;

        if (!username) {
            res.status(400);
            return;
        }

        if (!password) {
            res.status(400);
            return;
        }

        var newToken = {
            userId: user._id,
            token: uuid.v1(),
            created: new Date(),
        };

        res.status(200).json({
            token: newToken.token
        });
    });
};

References

  • UUID RFC.
  • Daniel Thatcher In GUID We Trust article.
  • UUID exploitation tool.
  • Common Weakness Enumeration: CWE-340.
python/ql/src/experimental/Security/CWE-340/TokenBuiltFromUUID.qhelp

Predictable token

GUIDs (often called UUIDs) are widely used in modern web applications. One common use for UUIDs is the generation of one-time-use tokens. These can used for password reset, and e-mail confirmation routines, for example.

There are five versions of UUIDs defined in RFC 4122. Out of the five, four are generated in a predictable manner. This means it is possible for someone to predict future UUIDs based on a sample generated by the target application.

Version four is the only UUID version expected to be randomly generated. Therefore, for situations where predictable tokens are not desired (e.g. password reset tokens), all other versions should be avoided.

Recommendation

When using GUIDs/UUIDs for generating tokens that should not be predictable, use version four.

Example

This example shows a UUID v1 being used for a password reset routine.

import uuid


class User:
    def __init__(self):
        self.token = None

    def resetPassword(self):
        self.token = uuid.uuid1().hex


user = User()
user.resetPassword()

References

  • UUID RFC.
  • Daniel Thatcher In GUID We Trust article.
  • UUID exploitation tool.
  • Common Weakness Enumeration: CWE-340.

Copy link
Copy Markdown
Contributor

The QHelp check is failing. You can see the error in the comment above.

Have you checked out the SensitiveNode class in JS? I think that could be useful for this query.

tausbn commented Oct 24, 2022

Copy link
Copy Markdown
Contributor

@bananabr Are you planning on applying for a GitHub Security Lab bounty for this PR?
I wasn't able to find a bounty issue for this PR.

Copy link
Copy Markdown
Contributor Author

@bananabr Are you planning on applying for a GitHub Security Lab bounty for this PR? I wasn't able to find a bounty issue for this PR.

Not at this time @tausbn.

tausbn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you for your submission!

Overall, the Python bits look really solid to me. I have made a bunch of suggestions for improvements, mostly to help you learn how to use the Python QL libraries even more effectively.

Let me know if I need to elaborate on anything. 🙂

…UUID.ql

Co-authored-by: Erik Krogh Kristensen <erik-krogh@github.com>

erik-krogh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

JS parts look OK for an experimental query.

tausbn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks again!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL