GithubHelp home page GithubHelp logo

authress-engineering / dynamodb-armor Goto Github PK

View Code? Open in Web Editor NEW
22.0 22.0 0.0 110 KB

Drop in replacement for DynamoDB, 100% compatible, protects against common production problems

License: Apache License 2.0

JavaScript 100.00%

dynamodb-armor's People

Contributors

wparad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dynamodb-armor's Issues

Add query related validations

const keyExpressionTokens = parseExpression(originalParams.KeyConditionExpression);
    const filterExpressionTokens = parseExpression(originalParams.FilterExpression);
    const matchingFilterExpressionKey = Object.keys(filterExpressionTokens.keys).some(filterKey => Object.keys(keyExpressionTokens.keys)
    .some(keyKey => originalParams.ExpressionAttributeNames[keyKey] === originalParams.ExpressionAttributeNames[filterKey]));
    
    // TODO: convert this from a error generation to in memory filtering
    if (matchingFilterExpressionKey) {
      throw new DynamoDbError({ title: 'DynamoDB disallows having a FilterExpression contain ', key: matchingFilterExpressionKey, parameters: originalParams }, 'InvalidExpression');
    }

Extend expression validation to handle complex UpdateExpressions

Example:

for (const partialExpression of partialExpressions) {
    const partialExpressionOrderedTokens = (partialExpression || '').replace(/^(DELETE|ADD|SET|REMOVE)\s+/i, '')
    .trim().split(',').filter(token => token).map(token => token.trim());

    const isValidKey = operand => operand.match(/^#\w+(\.#\w)*$/);
    const isValidOperand = operand => operand.match(/^:\w+$/) || operand.match(/^(#\w+(\.#\w)*|:\w+)[-+](#\w+(\.#\w)*|:\w+)$/);
    
    const arrayIterator = partialExpressionOrderedTokens[Symbol.iterator]();
    let result;
    
    while ((result = arrayIterator.next()) && !result.done) {
      const key = arrayIterator.next().value;
      const equalSign = arrayIterator.next().value;
      const operand = arrayIterator.next().value;

      if (!isValidKey(key) || equalSign !== '=' || !isValidOperand(operand)) {
        logger({ code: 'InvalidExpression', expression });
        throw new DynamoDbError({
          title: 'Invalid Expression: the expression does not match what DynamoDB expects: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html', expression,
          tokens: [key, equalSign, operand]
        }, 'InvalidExpression');
      }
      
      // parseExpressionRecursive(token, orderedTokens);
    }
  }

Force error on invalid BETWEEN expression

Where the latter comes after former (we don't want to automatically switch these, because if it isn't intentional, and we want to stop at X, stopping at Y which is later will cause a bug for the implementation.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.