This file is indexed.

/usr/share/xul-ext/refcontrol/components/refcontrolComp.js is in xul-ext-refcontrol 0.8.16-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
function refcontrolObserver() {}
refcontrolObserver.prototype = {
	
	bEnabled: true,
	aRefActions: {},
	
	dump: function dump(aMessage)
	{
		var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
		consoleService.logStringMessage("RefControl: " + aMessage);
	},
	
	dumpEx: function dumpEx(aException)
	{
		Components.utils.reportError(aException);
		if ('stack' in aException)
		{
			var msg = new String(aException);
			msg += "\n" + aException.stack;
			this.dump(msg);
		}
	},

	is3rdPartyRequest: function is3rdPartyRequest(oChannel)
	{
		return	(oChannel.referrer != null) && 
				(oChannel.URI.host != oChannel.referrer.host);
	},
	
	genRandLabel: function genRandLabel()
	{
		var chain =
		{
			a: 'lnrst',
			d: 'e',
			e: 'adnrst',
			h: 'aei',
			i: 'nst',
			l: 'de',
			n: 'dgt',
			o: 'fnru',
			r: 'ae',
			s: 'aeit',
			t: 'ehio',
			u: 'r',
			v: 'e',
		};
		var ret = '';
		var len = 3 + parseInt(Math.random() * 8);
		var next_chars = undefined;
		for (i = 0; i < len; i++)
		{
			if (next_chars === undefined)
				next_chars = "adehilnorstuv";
			var ch = next_chars[parseInt(Math.random() * next_chars.length)];
			ret += ch;
			next_chars = chain[ch];
		}
		return ret;
	},
	
	performVariableInterpolation: function performVariableInterpolation(oChannel, sRef)
	{
		var vars = { '$': '$' };	// $$ is a literal $
		var arr = 
		[ 
			{ name: 'URL', uri: oChannel.URI }, 
			{ name: 'REF', uri: oChannel.referrer }
		];
		for (var i in arr)
		{
			var o = arr[i];
			if (o.uri)
			{
				vars[o.name]				= o.uri.spec;
				vars[o.name + "_PREPATH"]	= o.uri.prePath;
				vars[o.name + "_SCHEME"]	= o.uri.scheme;
				vars[o.name + "_USERPASS"]	= o.uri.userPass;
				vars[o.name + "_USERNAME"]	= o.uri.username;
				vars[o.name + "_PASSWORD"]	= o.uri.password;
				vars[o.name + "_HOSTPORT"]	= o.uri.hostPort;
				vars[o.name + "_HOST"]		= o.uri.host;
				vars[o.name + "_PORT"]		= 
					o.uri.port != -1 ? 
					o.uri.port : 
					o.uri.schemeIs('http') ? 80 : 
					o.uri.schemeIs('https') ? 443 : 
					o.uri.port;
				vars[o.name + "_PATH"]		= o.uri.path;
			}
		}

		var genRandLabel = this.genRandLabel;
		return sRef.replace(
						/\$\{(\$|[a-zA-Z0-9_]*)\}|\$(\$|[a-zA-Z0-9_]*)/g, 
						function (str, match1, match2)
						{
							var var_name = match1 ? match1 : match2;
							if (var_name == 'RAND')
								return genRandLabel();
							else
								return vars[var_name] ? vars[var_name] : "";
						}
					);
	},

	adjustRef: function adjustRef(oChannel, sSite)
	{
		try {
			var sRef;
			var refAction = this.aRefActions[sSite];
			if (refAction == undefined)
				return false;

			if (refAction.if3rdParty && !this.is3rdPartyRequest(oChannel))
				return false;
				
			if (refAction.str.charAt(0) == '@')
			{
				// special actions
				switch (refAction.str)
				{
					case '@NORMAL':		// act as if we weren't here
						return true;
					case '@FORGE':		// use target's prepath
//						sRef = oChannel.URI.prepath;
						sRef = oChannel.URI.scheme + "://" + oChannel.URI.hostPort + "/";
						break;
					default:
						this.dump("adjustRef: unknown RefAction: " + refAction.str);
						return false;
				}
			}
			else
				sRef = this.performVariableInterpolation(oChannel, refAction.str);

//this.dump("adjustRef: setting Referer for " + oChannel.URI.spec + " to " + sRef);
			oChannel.setRequestHeader("Referer", sRef, false);
			if (oChannel.referrer)
				oChannel.referrer.spec = sRef;

			return true;
		} catch (ex) {
			this.dumpEx(ex);
		}
		return false;
	},

	onModifyRequest: function onModifyRequest(oHttpChannel)
	{
		if (!this.bEnabled)
			return;
		
		oHttpChannel.QueryInterface(Components.interfaces.nsIChannel);

		// handle wildcarding
		// try matching "www.foo.example.com", "foo.example.com", "example.com", ...
		for (var s = oHttpChannel.URI.host; s != ""; s = s.replace(/^.*?(\.|$)/, ""))
		{
			if (this.adjustRef(oHttpChannel, s))
				return;
		}
		// didn't find any matches, fall back on configured default action
		this.adjustRef(oHttpChannel, '@DEFAULT');
	},

	getActionsFromBranch: function getActionsFromBranch(oPrefBranch)
	{
		function myDecodeURI(sEncodedURI)
		{
			if (sEncodedURI.charAt(0) == '@')
				return sEncodedURI;
			try {
				return decodeURI(sEncodedURI);
			} catch (ex) {
				return sEncodedURI;
			}
		}

		var sActions = oPrefBranch.getCharPref('actions');
		
		var aRefActions = {};
		aRefActions['@DEFAULT'] = { str: '@NORMAL', if3rdParty: false };	// in case it is not in the pref
		
		var aActions = sActions.split(' ');
		for (var i in aActions)
		{
			var aKV = aActions[i].match(/(.*?)=(.*)/);
			if (aKV != null)
			{
				var s3rdParty = '@3RDPARTY';
				var res;
				if (aKV[2].substr(0, s3rdParty.length) == s3rdParty)
					res = { str: myDecodeURI(aKV[2].substr(s3rdParty.length + 1)), if3rdParty: true };
				else
					res = { str: myDecodeURI(aKV[2]), if3rdParty: false };
				aRefActions[aKV[1]] = res;
			}
		}
		
		return aRefActions;
	},

	onChangeEnabled: function onChangeEnabled(oPrefBranch)
	{
		this.bEnabled = oPrefBranch.getBoolPref('enabled');
	},
	
	onChangeActions: function onChangeActions(oPrefBranch)
	{
		this.aRefActions = this.getActionsFromBranch(oPrefBranch);
	},

	onAppStartup: function onAppStartup()
	{
		var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
		observerService.addObserver(this, "http-on-modify-request", true);
		
		var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
		this.prefBranch = prefService.getBranch("refcontrol.");
		this.prefBranch.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
		this.prefBranch.addObserver("enabled", this, true);
		this.prefBranch.addObserver("actions", this, true);
		this.onChangeEnabled(this.prefBranch);
		this.onChangeActions(this.prefBranch);
	},

	// Implement nsIObserver
	observe: function observe(aSubject, aTopic, aData)
	{
//this.dump("observe: " + aTopic);
		try {
			switch (aTopic)
			{
				case 'http-on-modify-request':
					if (aSubject instanceof Components.interfaces.nsIHttpChannel) {
						this.onModifyRequest(aSubject);
					}
					break;
				
				case 'nsPref:changed':
					aSubject.QueryInterface(Components.interfaces.nsIPrefBranch);
					switch (aData)
					{
						case 'enabled':
							this.onChangeEnabled(aSubject);
							break;
						case 'actions':
							this.onChangeActions(aSubject);
							break;
						default:
							this.dump("observe: unknown pref changing: " + aData);
							break;
					}
					break;
					
				case 'app-startup':
				case 'profile-after-change':
					this.onAppStartup();
					break;
					
				default:
					this.dump("observe: unknown topic: " + aTopic);
					break;
			}
		} catch (ex) {
			this.dumpEx(ex);
		}
	},
	
	// Implement nsISupports
	QueryInterface: function QueryInterface(iid)
	{
		if (!iid.equals(Components.interfaces.nsISupports) &&
			!iid.equals(Components.interfaces.nsIObserver) &&
			!iid.equals(Components.interfaces.nsISupportsWeakReference))
			throw Components.results.NS_ERROR_NO_INTERFACE;
		
		return this;
    },
	
	classDescription: "RefControl observer",
	contractID: "@mozilla.org/refcontrol;1",
	classID: Components.ID("{07C3DD15-0F44-4723-94DE-720B3B2FF9AF}"),
	_xpcom_categories: [{category: 'profile-after-change'}]
};

try {
	Components.utils["import"]("resource://gre/modules/XPCOMUtils.jsm");
	
	if (XPCOMUtils.generateNSGetFactory) {
		// moz-2.0+
		var NSGetFactory = XPCOMUtils.generateNSGetFactory([refcontrolObserver]);
	}
	else {
		// moz-1.9
		if (!XPCOMUtils.defineLazyGetter) {
			// moz < 1.9.2; no profile-after-change category, needs service:true
			refControlObserver.prototype._xpcom_categories = [{category: 'app-startup', service: true}];
		}
		function NSGetModule() { return XPCOMUtils.generateModule([refcontrolObserver]); }
	}	
}
catch (ex) {
	// legacy code < moz-1.9
	var refcontrolModule = {
		firstTime:		true,

		// Implement nsIModule
		registerSelf: function registerSelf(compMgr, fileSpec, location, type)
		{
			var rcp = refcontrolObserver.prototype;
			if (this.firstTime)
			{
				this.firstTime = false;
				throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
			}

			compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
			compMgr.registerFactoryLocation(rcp.classID, rcp.classDescription, rcp.contractID,
											fileSpec, location, type);

			var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
			catMan.addCategoryEntry("app-startup", "RefControl", rcp.contractID, true, true);
		},

		unregisterSelf: function unregisterSelf(compMgr, fileSpec, location)
		{
			var rcp = refcontrolObserver.prototype;
			
			// Remove the auto-startup
			compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
			compMgr.unregisterFactoryLocation(rcp.classID, fileSpec);

			var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
			catMan.deleteCategoryEntry("app-startup", rcp.contractID, true);
		},

		getClassObject: function getClassObject(compMgr, cid, iid)
		{
			var rcp = refcontrolObserver.prototype;
			if (!cid.equals(rcp.classID))
				throw Components.results.NS_ERROR_FACTORY_NOT_REGISTERED;

			if (!iid.equals(Components.interfaces.nsIFactory))
				throw Components.results.NS_ERROR_NO_INTERFACE;

			return this.myFactory;
		},

		canUnload: function canUnload(compMgr) { return true; },
		// end Implement nsIModule

		myFactory: {
			// Implement nsIFactory
			obj: null,
			createInstance: function createInstance(outer, iid)
			{
				if (outer != null)
					throw Components.results.NS_ERROR_NO_AGGREGATION;
				
				if (!this.obj) {
					this.obj = new refcontrolObserver();
				}
				return this.obj.QueryInterface(iid);
			}
		}
	};

	/* module initialisation */
	function NSGetModule(comMgr, fileSpec) { return refcontrolModule; }
}