Project

General

Profile

« Previous | Next » 

Revision ecb78704

Added by jahoti about 2 years ago

Streamline and harden unique values/settings

The base URL is now included in the settings. The unique value no longer uses
it directly, as it is included by virtue of the settings; however, the number
of full hours since the epoch (UTC) is now incorporated.

View differences:

common/misc.js
104 104
    return !!/^(chrome(-extension)?|moz-extension):\/\/|^about:/i.exec(url);
105 105
}
106 106

  
107
/* Sign a given policy for a given time */
108
function sign_policy(policy, now, hours_offset) {
109
    let time = Math.floor(now / 3600000) + (hours_offset || 0);
110
    return gen_unique(time + policy);
111
}
112

  
107 113
/* Extract any policy present in the URL */
108 114
function url_extract_policy(url)
109 115
{
110
    var policy_string;
111 116
    const targets = url_extract_target(url);
117
    if (!targets.target)
118
	return targets;
119

  
120
    /* %7B -> { */
121
    const index = targets.target.indexOf('%7B');
122
    if (index === -1)
123
	return targets;
124
    
125
    const now = new Date();
126
    const sig = targets.target.substring(1, index);
127
    const policy = targets.target.substring(index);
128
    if (
129
	sig !== sign_policy(policy, now) &&
130
	sig !== sign_policy(policy, now, -1) &&
131
	sig !== sign_policy(policy, now, 1)
132
    )
133
	return targets;
112 134
    
113 135
    try {
114
	policy_string = targets.target.substring(65);
115
	targets.policy = JSON.parse(decodeURIComponent(policy_string));
136
	targets.policy = JSON.parse(decodeURIComponent(policy));
137
	targets.current = targets.policy.base_url === targets.base_url;
116 138
    } catch (e) {
117 139
	/* TODO what should happen here? */
118 140
    }
119
    
120
    if (targets.policy) {
121
	const sig = gen_unique(policy_string + targets.base_url);
122
	targets.valid_sig = targets.target.substring(1, 65) === sig;
123
    }
124 141

  
125 142
    return targets;
126 143
}
......
132 149
 * EXPORT url_item
133 150
 * EXPORT url_extract_target
134 151
 * EXPORT url_extract_policy
152
 * EXPORT sign_policy
135 153
 * EXPORT csp_rule
136 154
 * EXPORT nice_name
137 155
 * EXPORT open_in_settings

Also available in: Unified diff