1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_
#include <cstddef>
#include <cstdint>
#include <string_view>
#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h"
#include "extensions/common/api/declarative_net_request/constants.h"
namespace extensions::declarative_net_request {
// The result of parsing JSON rules provided by an extension. Corresponds to a
// single rule.
enum class ParseResult {
NONE,
SUCCESS,
ERROR_REQUEST_METHOD_DUPLICATED,
ERROR_RESOURCE_TYPE_DUPLICATED,
ERROR_INVALID_RULE_ID,
ERROR_INVALID_RULE_PRIORITY,
ERROR_NO_APPLICABLE_RESOURCE_TYPES,
ERROR_EMPTY_DOMAINS_LIST,
ERROR_EMPTY_INITIATOR_DOMAINS_LIST,
ERROR_EMPTY_REQUEST_DOMAINS_LIST,
ERROR_DOMAINS_AND_INITIATOR_DOMAINS_BOTH_SPECIFIED,
ERROR_EXCLUDED_DOMAINS_AND_EXCLUDED_INITIATOR_DOMAINS_BOTH_SPECIFIED,
ERROR_EMPTY_RESOURCE_TYPES_LIST,
ERROR_EMPTY_REQUEST_METHODS_LIST,
ERROR_EMPTY_URL_FILTER,
ERROR_INVALID_REDIRECT_URL,
ERROR_DUPLICATE_IDS,
// Parse errors related to fields containing non-ascii characters.
ERROR_NON_ASCII_URL_FILTER,
ERROR_NON_ASCII_DOMAIN,
ERROR_NON_ASCII_EXCLUDED_DOMAIN,
ERROR_NON_ASCII_INITIATOR_DOMAIN,
ERROR_NON_ASCII_EXCLUDED_INITIATOR_DOMAIN,
ERROR_NON_ASCII_REQUEST_DOMAIN,
ERROR_NON_ASCII_EXCLUDED_REQUEST_DOMAIN,
ERROR_INVALID_URL_FILTER,
ERROR_INVALID_REDIRECT,
ERROR_INVALID_EXTENSION_PATH,
ERROR_INVALID_TRANSFORM_SCHEME,
ERROR_INVALID_TRANSFORM_PORT,
ERROR_INVALID_TRANSFORM_QUERY,
ERROR_INVALID_TRANSFORM_FRAGMENT,
ERROR_QUERY_AND_TRANSFORM_BOTH_SPECIFIED,
ERROR_JAVASCRIPT_REDIRECT,
ERROR_EMPTY_REGEX_FILTER,
ERROR_NON_ASCII_REGEX_FILTER,
ERROR_INVALID_REGEX_FILTER,
ERROR_REGEX_TOO_LARGE,
ERROR_MULTIPLE_FILTERS_SPECIFIED,
ERROR_REGEX_SUBSTITUTION_WITHOUT_FILTER,
ERROR_INVALID_REGEX_SUBSTITUTION,
ERROR_INVALID_ALLOW_ALL_REQUESTS_RESOURCE_TYPE,
// Parse errors related to fields specific to modifyheaders rules.
ERROR_NO_HEADERS_TO_MODIFY_SPECIFIED,
ERROR_EMPTY_MODIFY_REQUEST_HEADERS_LIST,
ERROR_EMPTY_MODIFY_RESPONSE_HEADERS_LIST,
ERROR_INVALID_HEADER_TO_MODIFY_NAME,
ERROR_INVALID_HEADER_TO_MODIFY_VALUE,
ERROR_HEADER_VALUE_NOT_SPECIFIED,
ERROR_HEADER_VALUE_PRESENT,
ERROR_APPEND_INVALID_REQUEST_HEADER,
// Parse errors related to matching on tab IDs.
ERROR_EMPTY_TAB_IDS_LIST,
ERROR_TAB_IDS_ON_NON_SESSION_RULE,
ERROR_TAB_ID_DUPLICATED,
// Parse errors related to matching on response headers.
ERROR_EMPTY_RESPONSE_HEADER_MATCHING_LIST,
ERROR_EMPTY_EXCLUDED_RESPONSE_HEADER_MATCHING_LIST,
ERROR_INVALID_MATCHING_RESPONSE_HEADER_NAME,
ERROR_INVALID_MATCHING_EXCLUDED_RESPONSE_HEADER_NAME,
ERROR_INVALID_MATCHING_RESPONSE_HEADER_VALUE,
ERROR_MATCHING_RESPONSE_HEADER_DUPLICATED,
ERROR_RESPONSE_HEADER_RULE_CANNOT_MODIFY_REQUEST_HEADERS,
};
// Describes the ways in which updating dynamic rules can fail.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class UpdateDynamicRulesStatus {
kSuccess = 0,
kErrorReadJSONRules = 1,
kErrorRuleCountExceeded = 2,
// kErrorCreateTemporarySource_Deprecated = 3,
// kErrorWriteTemporaryJSONRuleset_Deprecated = 4,
// kErrorWriteTemporaryIndexedRuleset_Deprecated = 5,
kErrorInvalidRules = 6,
kErrorCreateDynamicRulesDirectory = 7,
// kErrorReplaceIndexedFile_Deprecated = 8,
// kErrorReplaceJSONFile_Deprecated = 9,
kErrorCreateMatcher_InvalidPath = 10,
kErrorCreateMatcher_FileReadError = 11,
kErrorCreateMatcher_ChecksumMismatch = 12,
kErrorCreateMatcher_VersionMismatch = 13,
kErrorRegexTooLarge = 14,
kErrorRegexRuleCountExceeded = 15,
kErrorSerializeToJson = 16,
kErrorWriteJson = 17,
kErrorWriteFlatbuffer = 18,
kErrorUnsafeRuleCountExceeded = 19,
// Magic constant used by histograms code. Should be equal to the largest enum
// value.
kMaxValue = kErrorUnsafeRuleCountExceeded,
};
// Describes the result of loading a single JSON Ruleset.
// This is logged as part of UMA. Hence existing values should not be re-
// numbered or deleted.
enum class LoadRulesetResult {
// Ruleset loading succeeded.
kSuccess = 0,
// Ruleset loading failed since the provided path did not exist.
kErrorInvalidPath = 1,
// Ruleset loading failed due to a file read error.
kErrorCannotReadFile = 2,
// Ruleset loading failed due to a checksum mismatch.
kErrorChecksumMismatch = 3,
// Ruleset loading failed due to version header mismatch.
// TODO(karandeepb): This should be split into two cases:
// - When the indexed ruleset doesn't have the version header in the
// correct format.
// - When the indexed ruleset's version is not the same as that used by
// Chrome.
kErrorVersionMismatch = 4,
// Ruleset loading failed since the checksum for the ruleset wasn't found in
// prefs.
kErrorChecksumNotFound = 5,
// Magic constant used by histograms code. Should be equal to the largest enum
// value.
kMaxValue = kErrorChecksumNotFound,
};
// Specifies whether and how extensions require host permissions to modify the
// request.
enum class HostPermissionsAlwaysRequired {
// In this case, all actions require host permissions to the request url and
// initiator.
kTrue,
// In this case, only redirecting (excluding upgrading) requests and modifying
// headers require host permissions to the request url and initiator.
kFalse,
};
// Specifies the request stage for which rulesets are to be matched.
enum class RulesetMatchingStage {
// At this stage, the request has been prepared but not sent. Rules with
// conditions based only on the request's parameters will be matched.
kOnBeforeRequest,
// At this stage, the request's headers have been sent and response headers
// have been received. Rules with conditions that depend on the request's
// response will be matched.
kOnHeadersReceived,
};
// Specifies what triggered a ruleset load for an extension.
enum class LoadRulesetRequestSource {
// The ruleset load was triggered when the extension is loaded. This will load
// enabled static rulesets and dynamic rules.
kOnExtensionLoad = 0,
// The ruleset load was triggered by an updateEnabledRulesets API call, which
// enabled a disabled ruleset.
kUpdateEnabledStaticRulesets = 1,
// The ruleset load was triggered by an updateDynamicRules API call.
kUpdateDynamicRules = 2,
};
// Schemes which can be used as part of url transforms.
extern const char* const kAllowedTransformSchemes[4];
// Rule parsing errors.
extern const char kErrorRequestMethodDuplicated[];
extern const char kErrorResourceTypeDuplicated[];
extern const char kErrorInvalidRuleKey[];
extern const char kErrorNoApplicableResourceTypes[];
extern const char kErrorEmptyList[];
extern const char kErrorEmptyKey[];
extern const char kErrorInvalidRedirectUrl[];
extern const char kErrorDuplicateIDs[];
extern const char kErrorPersisting[];
extern const char kErrorNonAscii[];
extern const char kErrorInvalidKey[];
extern const char kErrorInvalidTransformScheme[];
extern const char kErrorQueryAndTransformBothSpecified[];
extern const char kErrorDomainsAndInitiatorDomainsBothSpecified[];
extern const char kErrorJavascriptRedirect[];
extern const char kErrorMultipleFilters[];
extern const char kErrorRegexSubstitutionWithoutFilter[];
extern const char kErrorInvalidAllowAllRequestsResourceType[];
extern const char kErrorRegexTooLarge[];
extern const char kErrorNoHeaderListsSpecified[];
extern const char kErrorInvalidModifyHeaderName[];
extern const char kErrorInvalidModifyHeaderValue[];
extern const char kErrorNoHeaderValueSpecified[];
extern const char kErrorHeaderValuePresent[];
extern const char kErrorAppendInvalidRequestHeader[];
extern const char kErrorTabIdsOnNonSessionRule[];
extern const char kErrorTabIdDuplicated[];
extern const char kErrorInvalidMatchingHeaderName[];
extern const char kErrorInvalidMatchingHeaderValue[];
extern const char kErrorResponseHeaderDuplicated[];
extern const char kErrorResponseHeaderRuleCannotModifyRequestHeaders[];
extern const char kErrorListNotPassed[];
// Rule indexing install warnings.
extern const char kRuleCountExceeded[];
extern const char kRegexRuleCountExceeded[];
extern const char kEnabledRuleCountExceeded[];
extern const char kEnabledRegexRuleCountExceeded[];
extern const char kRuleNotParsedWarning[];
extern const char kTooManyParseFailuresWarning[];
extern const char kIndexingRuleLimitExceeded[];
// Dynamic rules API errors.
extern const char kInternalErrorUpdatingDynamicRules[];
extern const char kInternalErrorGettingDynamicRules[];
extern const char kDynamicRuleCountExceeded[];
extern const char kDynamicUnsafeRuleCountExceeded[];
extern const char kDynamicRegexRuleCountExceeded[];
// Session-scoped rules API errors.
extern const char kSessionRuleCountExceeded[];
extern const char kSessionUnsafeRuleCountExceeded[];
extern const char kSessionRegexRuleCountExceeded[];
// Static ruleset toggling API errors.
extern const char kInvalidRulesetIDError[];
extern const char kEnabledRulesetsRuleCountExceeded[];
extern const char kEnabledRulesetsRegexRuleCountExceeded[];
extern const char kInternalErrorUpdatingEnabledRulesets[];
extern const char kEnabledRulesetCountExceeded[];
// Static rule toggling API errors.
extern const char kDisabledStaticRuleCountExceeded[];
// setExtensionActionOptions API errors.
extern const char kTabNotFoundError[];
extern const char kIncrementActionCountWithoutUseAsBadgeTextError[];
// testMatchOutcome API errors.
extern const char kInvalidTestURLError[];
extern const char kInvalidTestInitiatorError[];
extern const char kInvalidTestTabIdError[];
extern const char kInvalidResponseHeaderObjectError[];
extern const char kInvalidResponseHeaderNameError[];
extern const char kInvalidResponseHeaderValueError[];
// Histogram names.
extern const char kIndexAndPersistRulesTimeHistogram[];
extern const char kManifestEnabledRulesCountHistogram[];
extern const char kUpdateDynamicRulesStatusHistogram[];
extern const char kReadDynamicRulesJSONStatusHistogram[];
extern const char kIsLargeRegexHistogram[];
extern const char kRegexRuleSizeHistogram[];
extern const char kLoadRulesetResultHistogram[];
// Placeholder text to use for getBadgeText extension function call, when the
// badge text is set to the DNR action count.
extern const char kActionCountPlaceholderBadgeText[];
// Error returned for the getMatchedRules extension function call, if the
// extension does not have sufficient permissions to make the call.
extern const char kErrorGetMatchedRulesMissingPermissions[];
// The maximum amount of static rules in the global rule pool for a single
// profile.
inline constexpr int kMaxStaticRulesPerProfile = 300000;
// The per-extension maximum amount of disabled static rules.
inline constexpr int kMaxDisabledStaticRules = 5000;
// Maximum size of a compiled RegEx rule in KB. Limited to 2 KB which means
// that given 1024 rules, the total usage would be 2 MB.
inline constexpr int kRegexMaxMemKb = 2;
// Identifier for a Flatbuffer containing `flat::EmbedderConditions` as the
// root.
extern const char kEmbedderConditionsBufferIdentifier[];
// An allowlist of request headers that can be appended onto, in the form of
// (header name, header delimiter). Currently, this list contains all standard
// HTTP request headers that support multiple values in a single entry. This
// list may be extended in the future to support custom headers.
inline constexpr auto kDNRRequestHeaderAppendAllowList =
base::MakeFixedFlatMap<std::string_view, std::string_view>(
{{"accept", ", "},
{"accept-encoding", ", "},
{"accept-language", ", "},
{"access-control-request-headers", ", "},
{"cache-control", ", "},
{"connection", ", "},
{"content-language", ", "},
{"cookie", "; "},
{"forwarded", ", "},
{"if-match", ", "},
{"if-none-match", ", "},
{"keep-alive", ", "},
{"range", ", "},
{"te", ", "},
{"trailer", ""},
{"transfer-encoding", ", "},
{"upgrade", ", "},
{"user-agent", " "},
{"via", ", "},
{"want-digest", ", "},
{"x-forwarded-for", ", "}});
} // namespace extensions::declarative_net_request
#endif // EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_
|