Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Discussion about new ruleset format. #12620

Closed

Description

type: other

This is the format I currently have in mind:

// Comments are allowed, and will be stripped before combining the rulesets into a ruleset library.
{
  "name": "0bin.net",

  // "platform" and "default_off" are no longer supported. Use problematic targets instead.

  /**
   * Problematic targets are also tested. If a problematic target no longer has the specified
   * error, Travis test fails.
   *
   * Problematic targets may be enabled by the user, e.g. mixedcontent or cacert ones.
   *
   * Problematic targets are copied into the ruleset library depending on the reason.
   *
   * Targets may have "rules" property for rules specific to this target. If a target has "rules"
   * property, global rules are ignored.
   */
  "targets": {
    "0bin.net": {
      "rules": [
        {
          "from": "^/testURL$",
          "to": "https://0bin.net/testURL4",
          "tests": [ "http://0bin.net/testURL" ]
        },
        {
          "forceHTTPS": true,
          "exclusions": [
            {
              "pattern": "^/testURL2$",
              "tests": [ "http://0bin.net/testURL2" ]
            }
          ]
        }
      ]
    },
    "www.0bin.net": {
      "rules": [
        {
          "from": "^/",
          "to": "https://0bin.net/"
        }
      ]
    },
    "gay.0bin.net": {
      "problems": [ "redirect-loop" ]
    }
  },

  /**
   * "secureCookies" may be an array of objects having "host" and "name" properties or may be true,
   * which will secure all cookies.
   */
  "secureCookies": true,

  /**
   * "rules" contain the rules which are applied if a target doesn't have its own "rules" property.
   * Rules should always be associated with a target if possible, unless most targets have the same
   * rules.
   */
  "rules": [
    /**
     * A rule should have "from" and "to" properties.
     *
     * A rule may have "tests" property for tests specific to this rule. It will not be copied
     * into the ruleset library.
     *
     * A rule may have "exclusions" property for exclusions specific to this rule.
     *
     * "rules" may be omitted, in this case it is assumed to be ["forceHTTPS"].
     */
    "force HTTPS"
  ],

  /*
   * Named rules allow to easily apply one rule to multiple targets. "forceHTTPS" is a built-in named
   * rule.
   */
  "namedRules": {
    // This rule is identical to the built-in "forceHTTPS" rule.
    "force HTTPS": { "from": "^http:", "to": "https:" }
  },

  /**
   * An exclusion may be either a string or an object having "pattern" and "tests" properties.
   *
   * Exclusions should always be associated with a rule if possible.
   */
  "exclusions": [],

  /**
   * "tests" contains tests that are global to the ruleset. Tests should always be associated with
   * a rule or an exclusion if possible.
   *
   * This property will not be copied into the ruleset library.
   */
  "tests": [ "http://0bin.net/testURL3" ]
}

It is recommended for rulesets to be hierarchical, only containing targets at root and having rules, exclusions and tests under each target.

Activity

  1. ghost changed the title [-]Discussion about JSON rulesets in the repository.[/-] [+]Discussion about new ruleset format.[/+] on Sep 18, 2017
  2. RReverser commented on Sep 18, 2017

    @RReverser
    Contributor

    I would also allow nesting rules under targets so that you could match only path part of URL and avoid duplication of hostnames in regexp for 90% of cases, so that example above would become something like:

    {
      "name": "0bin.net",
    
      "targets": {
        "0bin.net": {
          "tests": [
            "/testURL",
            "/testURL3"
          ],
          "exclusions": [
            {
              "pattern": "^/testURL2$",
              "tests": [ "/testURL2" ]
            }
          ]
        },
    
        "www.0bin.net": {
          "rules": {
            "from": "^/",
            "to": "https://0bin.net/"
          }
        },
    
        "gay.0bin.net": {
          "problems": [ "https2http" ]
        }
      },
    
      "secureCookies": true,
    
      "rules": [{
        "forceHTTPS": true
      }]
    }

    Note that it still allows defining rules global to the ruleset, but it won't be needed for most cases and such change would allow better refinement optimisations by the rewriter (as it needs to check fewer regexps when it already found the host).

  3. RReverser commented on Sep 18, 2017

    @RReverser
    Contributor

    @koops76

    url.replace(/^//, 'https://0bin.net/') is not going to work.

    Not directly, but it's easy to fix.

    What should be its value then, an empty object or true?

    I'd suggest null or empty object.

  4. RReverser commented on Sep 18, 2017

    @RReverser
    Contributor

    @koops76 You still have host duplication. Avoiding it is one of main benefits of nesting regexps under host target (you save memory, don't need to do extra matching etc.).

    url.replace(/^\//, 'https://0bin.net/') will work just fine, but for nested rules, as I said, only path part of URL should be passed.

  5. RReverser commented on Sep 18, 2017

    @RReverser
    Contributor

    It won't. As I said, only path part of the URL is passed to nested rules in that scheme (since you already know the host you're matching) so for http://0bin.net/x?y=1 you are just taking result of '/x?y=1'.replace(/^\//, 'https://0bin.net/') and using it as a final URL. No need to overcomplicate things :)

  6. RReverser commented on Sep 18, 2017

    @RReverser
    Contributor

    TL;DR - if rule wants to match entire URL, including host - it should be defined globally in ruleset JSON, if it already applies only to specific host and cares only about path part of the URL, it can be nested under corresponding target.

  7. J0WI commented on Sep 18, 2017

    @J0WI
    Contributor

    See also #3999.
    JSON is even worse to write than XML, especially for simple rule sets. YML would be easy, but not for complex ruleset. Maintain two different formats is also bad, so I think that's why we still use XML.

  8. J0WI commented on Sep 18, 2017

    @J0WI
    Contributor

    I would love to see such simple keywords like forceHTTPS and secureCookies.

    "platform" and "default_off" are no longer supported. Use problematic targets instead.
    Problematic targets are also tested. If a problematic target no longer has the specified error, Travis test fails.

    How do exclusions and test urls work together with problematic targets? How does this work with wildcards?
    I'm a bit skeptic that we can maintain all problematic targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions